-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making getAddrInfo polymorphic #587
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth putting a {-# DEPRECATED #-}
on getAddrInfo
, and laying out a migration plan of:
- Remove
getAddrInfo
- Re-add
getAddrInfo = getAddrInfoNE
, deprecategetAddrInfoNE
- Remove
getAddrInfoNE
?
It is a nice idea to put |
It would be worth making Roughly, getAddrInfo
:: (??? t)
=> Maybe AddrInfo
-> Maybe HostName
-> Maybe ServiceName
-> IO (t AddrInfo)
``` |
Some thoughts, which might conflict with each other:
|
Network/Socket/Info.hsc
Outdated
-> IO (NE.NonEmpty AddrInfo) | ||
getAddrInfoNE hints node service = | ||
-- getAddrInfo never returns an empty list. | ||
NE.fromList <$> getAddrInfo hints node service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since getAddrInfoList
also does a non-empty check and throws an IO error if the list is empty, you could make getAddrInfoNE
the "real" function and implement getAddrInfoList
by fmapping toList
over the result of getAddrInfoNE
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
d97f57d
to
795cebb
Compare
I cannot find a way to deprecate instance from the GHC documentation. |
OK. Done. |
How about not allocating the head tuple when constucting the |
getAddrInfo | ||
class GetAddrInfo t where | ||
----------------------------------------------------------------------------- | ||
-- | Resolve a host or service name to one or more addresses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rendered the haddocks, and it doesn't give the reader a way to see what instances of GetAddrInfo
exist. I think we should document them here.
Alternatively, we could use the IsList
class? But I think that will be more confusing and should only be for -XOverloadedLists
support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that IsList
is confusing.
1411634 improves the doc.
IsList example: Applicative and Semigroup example: Which type signature would be better? |
I think |
@endgame I like the current implementation. |
Is this ready for merging? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some final thoughts, most small. I reworded the haddock too.
-- >>> addr <- NE.head <$> getAddrInfo (Just hints) (Just "127.0.0.1") (Just "http") | ||
-- >>> addrAddress addr | ||
-- 127.0.0.1:80 | ||
getAddrInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A @since
line might also be useful for future readers, to know when a NonEmpty
is available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Co-authored-by: endgame <[email protected]>
Co-authored-by: endgame <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good. One final nit (my fault, sorry) and a thought for future work. Thank you for this.
| ptr_ai == nullPtr = return [] | ||
-- POSIX requires that getaddrinfo(3) returns at least one addrinfo. | ||
-- See: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html | ||
| ptr_ai == nullPtr = ioError $ mkIOError NoSuchThing "getaddrinfo must return at least one addrinfo" Nothing Nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to capture errno
in the IO error, but that's out of scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error reporting of network
is historically poor.
We should implement a mechanism to maintain error numbers in the future.
Co-authored-by: endgame <[email protected]>
Merged. |
haskell#587 removed the call to c_freeaddrinfo in getAddrInfoNE. This restores it and in addition makes the function async exception safe.
haskell#587 removed the call to `c_freeaddrinfo` in `getaddrinfo`. This restores it and in addition makes the function async exception safe.
haskell#587 removed the call to `c_freeaddrinfo` in `getaddrinfo`. This restores it and in addition makes the function async exception safe.
haskell#587 removed the call to `c_freeaddrinfo` in `getaddrinfo`. This restores it and in addition makes the function async exception safe.
The recent GHCs warn partial pattern matchings and partial functions.
So, let's provide
getAddrInfoNE
:Since GHC 9.8 or later warn partial functions, I begin to think to provide:
@khibino Would you review this PR?