-
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
Socket type and family as CInt patterns #459
Socket type and family as CInt patterns #459
Conversation
Of course, I will support this approach. Please go ahead. |
My concern is whether there are any compatibility issues that I'm perhaps neglecting? Any thoughts about the "Read" instances? Should they be kept, or dropped? |
As a user of this library, I'd support moving existing |
Depending on your point of view, unfortunately, that boat sailed a long time ago. While I sympathise with the sentiment of wanting a round-trip-capable pair of Show and Read instances which parse as Haskell expression allowing My take is that the user seeing a friendly representation of the structure is more important... It is unfortunate that Haskell doesn't have a separate stock type class for "friendly" presentation of data, which would be used in error messages, ... Thus we find many libraries that violate the Read/Show contract, and are sometimes right to do so. In some DNS-related code I'm working on, I have a "present" method of a "Presentable" typeclass, used for showing DNS objects in "presentation form", which is far more useful to users than a technically correct Which is not to say that your point is invalid, it is just a matter of tradeoffs, and I am presently not sold on the idea of technically correct, but less usable. :-( |
TBH, I find custom Show instances often actually less usable when they hide the internal structure of the data (as some of these do here). Also if not well-thought-out, then the attempt to make the instance "look friendly" can actually leave it ambiguous, which can be pretty infuriating when debugging an error message. |
A fair point. I'm just saying that there's no single right answer. In this PR I am changing what were previously simple With more care, we could output |
68ad85a
to
6ecb798
Compare
@simonmar Can you comment on whether the |
38d2359
to
2ac0cc0
Compare
I decided to do as you essentially as you asked. While the Read/Show instances are not derived, they behave as you'd expect, modulo not bothering to support the more exotic |
The current sum-type model for Socket types and families is not extensible, and makes it needlessly difficult to perform generic operations on sockets, see e.g. haskell#427 This commit, simplifies the model by replacing the sum-types in question with newtypes around CInt + patterns for the known constant values. It also adds the SO_DOMAIN and SO_PROTOCOL options (when available on the target system). The "Read" instance for "Family" is for simplicify limited to just the address families actually supported by the library (unspec, inet, inet6 and unix). The rest could be added if deemed worth the trouble.
Does anyone know why they are needed?
2ac0cc0
to
24c0bfc
Compare
I am dropping the WIP tag, please review. I think this is ready, modulo perhaps adding a bunch more |
@cartazio Would you care to review this PR? |
Thanks, that sounds good! BTW, I didn't mean to apply a lot of pressure and ofc the maintainers of this package have the last say, if they might prefer what you had previously. Regarding the |
@vdukhovni Should the subject be "Removing |
There are two commits in this PR. While I was changing the definitions of The main feedback I'm looking for now is about the new |
First of all, I can accept this PR since there is no backward compatibility issue. |
@vdukhovni Do you worry about usability when we introduce patterns?
If so, we already have the same issue in |
Well, in this PR, the However, I hadn't yet bothered adding all the names for the exotic |
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.
This PR itself has no problem. Let's discuss patterns vs show instances in another issue.
Though this is merged (thanks again!), just wanted to check that you're satisfied with the "incomplete" |
I think that defining important values such as inet, inet6 and unix is sufficient. |
The current sum-type model for Socket types and families is not extensible, and
makes it needlessly difficult to perform generic operations on sockets, see
e.g. #427
This WIP (not yet done, preview), simplifies the model by replacing the sum
types in question with newtypes around CInt + patterns. It also adds the
SO_DOMAIN and SO_PROTOCOL options (when available on the target system).
Pre-review requested to sanity check the overall approach.
Open issues: