Support empty record definitions in parser#91
Merged
Conversation
Allow RRFields production to match zero or more fields, enabling empty record definitions. Fixed applicativeE to wrap empty lists in return, enabling proper JSON parsing for empty record types. Added test cases for empty records, mixed empty and filled records. Fixes #83.
When a record has zero fields, the TH code generators for various tool instances would bind variables (e.g. lambda parameters) that were never referenced in the body. With -Wall/-Wunused-matches, GHC flags these as warnings in the generated splices. Fix by using wildcard patterns (wildP) instead of named bindings (varP) when srFields is empty, across all affected generators: - Tools/JSON.hs (ToJSON): \x -> object [] => \_ -> object [] - Tools/JSON.hs (FromJSONWithErrs): (Object x) => (Object _) - Tools/QuickCheck.hs (Arbitrary): sized (\x -> pure Con) => sized (\_ -> ...) - Tools/DeepSeq.hs (NFData): \x -> () => \_ -> () - Tools/Example.hs (Example): sized (\x -> pure Con) => sized (\_ -> ...) - Tools/Traversal.hs (traversal): \f r -> pure Con => \_ _ -> pure Con
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.
Fixes #83.
This PR extends the parser to support this syntax:
Under the hood, this generates a Haskell datatype with a single "tag", i.e:
data EmptyRecord = EmptyRecord.This is actively used in this PR and it does the trick. While using it in Atlas I've got GHC to warn about some unused variables; it turns out that in a few places, when we generated TH definitions in the tools for the various instances, we could be generating things like:
(Like it would be the case now for an
EmptyRecord). This PR amends the TH generation to usewildPunder the right circumstances.