Change Show-instances to use "#field := val"#37
Open
Profpatsch wants to merge 5 commits intoagrafix:masterfrom
Open
Change Show-instances to use "#field := val"#37Profpatsch wants to merge 5 commits intoagrafix:masterfrom
"#field := val"#37Profpatsch wants to merge 5 commits intoagrafix:masterfrom
Conversation
Arguably, emptyVariant is more like Void than (), given that it is
actually not possible to obtain its value via fromVariant and if it
were, a program would explode due to undefined.
In JSON there is not really a way to have a void value, a JSON value is
always *something*, so it makes no sense to have a Variant '[] parser
that succeeds in any condition. More importantly, the FromJSON instance
for Variant (t ': ts) actually *requires* the instance for Variant '[]
to fail! If parseJSON is called for Variant '[] from that instance, it
means that the value didn't match any of the types the Variant accepts.
This causes the bug that, if parseJSON :: Parser () succeeds for a JSON
value, we can obtain an arbitrary Variant that would fail to evaluate,
as it'd be constructed via extendVariant emptyVariant. For aeson < 1.6
this is a pretty obscure bug, since FromJSON () only accepts the empty
array:
>>> decode "[]" :: Maybe (Variant '[Int])
Just *** Exception: Prelude.undefined
Since aeson 2.0, FromJSON () [accepts] all JSON values, meaning that any
failed parse to Variant results in a program crash!
Tagged Variants also exhibit this problem, of course. The bug is fixed
by making the FromJSON (Variant '[]) instance fail always via parseFail.
[accepts]: haskell/aeson@677daf0
This adds a bit more ifdef zoo to be compatible with the breaking change in aeson. Tested manually against aeson 2.0.3.0 and 1.5.6.0. Might want to update the CI as well, but I don’t have the time to touch CircleCI yaml. Co-authored-by: Lukas Epple <lukas.epple@possehl-analytics.com>
Support for * is disabled in GHC 9.2 by default and causes a lot of annoying warnings in 9.0. Tested against 8.10.7, 9.0.2 and 9.2.4. The base constraint seems to be correct, as Data.Kind was added in base 4.9. Co-authored-by: Lukas Epple <lukas.epple@possehl-analytics.com>
This seems to be required now to compile the Variant code.
The previous show instance would add another layer of quoting for each nesting: ``` ghci> show (rcons (#foo := "bar") rnil) "[(\"foo\",\"\\\"bar\\\"\")]" ``` Instead, what we want is to display a nicely readable variant of the record, using the infix field syntax for both label/value pairs and full records: ``` ghci> show (rcons (#hi := (rcons (#lea := "hi") rnil)) (rcons (#foo := "bar") rnil )) "[#foo := \"bar\",#hi := [(#lea := \"hi\")]]" ghci> show (#hi := "lea") "#hi := \"lea\"" ``` That’s better! Note that we can’t have a roundtripping `Read` instance anyway, so we might as well have `Show` be readable. Fixes agrafix#36
23d3873 to
05c8fdd
Compare
Author
|
Note that So in that case we might want to have a special case? Thoughts? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous show instance would add another layer of quoting for each
nesting:
Instead, what we want is to display a nicely readable variant of the
record, using the infix field syntax for both label/value pairs and
full records:
That’s better!
Note that we can’t have a roundtripping
Readinstance anyway, so wemight as well have
Showbe readable.Fixes #36
This includes the changes from #35