-
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
Precedence-compliant Read/Show instances using Bijective pairs for patterns #466
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.
Looks pretty good overall.
I'm requesting a couple of changes, and would like to see this squashed to a single commit.
Also perhaps some tests added to test round-trip correctness read (show x) == x
and a few select cases of explicit show x == "expected result"
.
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.
Looks great, thanks! Basically done.
I'm asking @kazu-yamamoto to also review, and it'd be good if someone would suggest better names for _show
and _parse
which show and read a pair of integers, presumably wrapped by some constructor or pattern synonym. The names don't make that clear. Otherwise, this is good.
@kazu-yamamoto: The reason for the name prefix (constructor or pattern for the generic case) being optional, is that if we decide to assign patterns for, e.g., protocol numbers, then the generic case is just a literal number, because protocol numbers would have a Num
instance even if they become newtype ProtocolNumber = ProtocolNumber CInt
. We might then display some common protocols via their pattern names, such as TCP
for 6
and UDP
as 17
, but most protocols would continue to display as just a number.
This looks excellent to me.
@archaephyrryx Could you add tests as @vdukhovni suggested? |
To me, these don't quite say "show/parse 2 consecutive numeric literals". So perhaps |
One difficulty is that the two functions convert between tuples of Integer-like values and strings containing a space-separated sequence of possibly-parenthesized integers. The tuple is necessary for |
I also plan on squashing several of the commits before this PR gets merged, once all outstanding concerns have been settled. Unless I am mistaken, rewriting the history of this branch would wipe the conversation history of this PR, so I am planning to hold off until things are resolved. In any case, instead of merging right away, let me know that you intend to merge so that I can reorganize the commits more naturally. |
Yes, getting the name to precisely capture the input/output types is difficult, and largely impractical. I still think that |
Would |
I have no preference, either is fine. |
Please feel free to edit your commits (maybe by |
Defines a CmsgIdFd pattern (unsupported) in Network.Socket.Win32.Cmsg and exports CmsgIdFd in Network.Socket
refactors and reimplements Network.Socket.ReadShow to allow for precedence-sensitive Read/Show instances built on an underlying bijective framework. Behavior conforms to derived read/show instances by default but short-circuits to fixed strings when input matches element of a list of paired elements defining a partial bijection. adds several flexible helper-functions to Network.Socket.ReadShow to allow for minimal-boilerplate implementations of bijective read/show for arbitrary types in future. Adds more descriptive documentation for non-obvious properties of Network.Socket.ReadShow types and functions reimplements instance declarations of read/show for types already using bijective read/show definitions Adds cases to Network.SocketSpec test suite to ensure that ReadShow-based Show instances produce expected output for each pattern-bijection type Adds quickcheck-dependent (updated cabal file) tests to ensure roundtrip equality for `read.show` for all types using ReadShow-based instances over arbitrary values, specifically biased towards pattern synonym values
1190063
to
710b6ca
Compare
I did the rebase and the commits organized a bit better. I am probably finished with working on this PR for now, unless there are any specific adjustments you think would be appropriate. Feel free to merge whenever. |
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.
LGTM
Merged. Thank you for your excellent work! If you have further plans, please let me know. |
Adapts bijective read/show boilerplate in Network.Socket.ReadShow to be precedence-sensitive while maintaining full generality of base implementation.
Re-implements bijective read/show instances for SocketOption, SocketType, Family, and CmsgId.