-
Notifications
You must be signed in to change notification settings - Fork 2
Support sets #79
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
Open
adinapoli
wants to merge
4
commits into
master
Choose a base branch
from
adinapoli/experiment-in-supporting-sets
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Support sets #79
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
37cab74
Support set types in API schemas
adinapoli 47de6e2
Fix set support gaps: traversals, lexer keywords, migration tests
adinapoli 9c69f49
Test that sets decode from arrays, not objects
adinapoli 7db43fe
Address review: keep SetList, document why, tidy Traversal exports
adinapoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,11 @@ import Prelude | |
| -- traversals generated automatically: if required, these must be | ||
| -- defined manually in the same module as the call to 'traversalTool', | ||
| -- otherwise the generated code will lead to scope errors. | ||
| -- | ||
| -- If the schema uses sets, the generated traversals of set-valued | ||
| -- fields are not lawful 'Traversal's (they cannot be, because | ||
| -- 'Set.Set' is not a 'Functor'): they may coalesce multiple elements | ||
| -- that are mapped to the same value. | ||
| traversalTool :: TypeName -> TypeName -> APITool | ||
| traversalTool root = traversalsTool [root] | ||
|
|
||
|
|
@@ -73,6 +78,12 @@ traversalType x an = [t| forall f . Applicative f => ($x' -> f $x') -> $ty -> f | |
| ty = nodeT an | ||
|
|
||
|
|
||
| -- | Traverse the elements of a 'Set.Set'. This is not a lawful 'Traversal' | ||
| -- (it cannot be, because 'Set.Set' is not a 'Functor'), but it is what the | ||
| -- traversals generated by 'traversalsTool' use for set-valued fields. | ||
|
Comment on lines
+81
to
+83
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add this to the comments on |
||
| traverseSet :: (Applicative f, Ord b) => (a -> f b) -> Set.Set a -> f (Set.Set b) | ||
| traverseSet f = fmap Set.fromList . traverse f . Set.toList | ||
|
|
||
| -- | Construct a traversal of the X substructures of the given type | ||
| traverser :: NormAPI -> Set.Set TypeName -> TypeName -> APIType -> ExpQ | ||
| traverser napi targets x ty = fromMaybe [| const pure |] $ traverser' napi targets x ty | ||
|
|
@@ -81,6 +92,11 @@ traverser napi targets x ty = fromMaybe [| const pure |] $ traverser' napi targe | |
| -- or return 'Nothing' if there are no substructures to traverse | ||
| traverser' :: NormAPI -> Set.Set TypeName -> TypeName -> APIType -> Maybe ExpQ | ||
| traverser' napi targets x (TyList ty) = fmap (appE [e|(.) traverse|]) $ traverser' napi targets x ty | ||
| -- 'Data.Set.Set' is not 'Traversable' (the element type is constrained by | ||
| -- 'Ord'), but we can still traverse the elements via the element list. Note | ||
| -- that this may shrink the set, if the function maps distinct elements of the | ||
| -- original set to the same value. | ||
| traverser' napi targets x (TySet ty) = fmap (appE [e|(.) traverseSet|]) $ traverser' napi targets x ty | ||
| traverser' napi targets x (TyMaybe ty) = fmap (appE [e|(.) traverse|]) $ traverser' napi targets x ty | ||
| traverser' napi targets x (TyName tn) | ||
| | tn == x = Just [e| id |] | ||
|
|
||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.