Skip to content

Commit 3bc61f1

Browse files
committed
IsList result of getAddrInfo
1 parent cbb5b59 commit 3bc61f1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Network/Socket/Info.hsc

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE TypeOperators #-}
23
{-# LANGUAGE RecordWildCards #-}
34
{-# OPTIONS_GHC -fno-warn-orphans #-}
45

@@ -11,6 +12,8 @@ import Data.List.NonEmpty (NonEmpty(..))
1112
import qualified Data.List.NonEmpty as NE
1213
import Foreign.Marshal.Alloc (alloca, allocaBytes)
1314
import Foreign.Marshal.Utils (maybeWith, with)
15+
import GHC.IsList (IsList (..))
16+
import qualified GHC.IsList as IsList
1417
import GHC.IO.Exception (IOErrorType(NoSuchThing))
1518
import System.IO.Error (ioeSetErrorString, mkIOError)
1619

@@ -245,6 +248,13 @@ defaultHints = AddrInfo {
245248
-- >>> addr <- NE.head <$> getAddrInfo (Just hints) (Just "127.0.0.1") (Just "http")
246249
-- >>> addrAddress addr
247250
-- 127.0.0.1:80
251+
getAddrInfo
252+
:: (Item l ~ AddrInfo, IsList l)
253+
=> Maybe AddrInfo -- ^ preferred socket type or protocol
254+
-> Maybe HostName -- ^ host name to look up
255+
-> Maybe ServiceName -- ^ service name to look up
256+
-> IO l -- ^ resolved addresses, with "best" first
257+
getAddrInfo hints node service = IsList.fromList . NE.toList <$> getAddrInfoNE hints node service
248258

249259
getAddrInfoNE
250260
:: Maybe AddrInfo -- ^ preferred socket type or protocol

0 commit comments

Comments
 (0)