Skip to content
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

[Design] Use higher-kinded data #39

Closed
serras opened this issue Dec 9, 2019 · 0 comments · Fixed by #41
Closed

[Design] Use higher-kinded data #39

serras opened this issue Dec 9, 2019 · 0 comments · Fixed by #41
Assignees
Labels
enhancement New feature or request

Comments

@serras
Copy link
Collaborator

serras commented Dec 9, 2019

Inspired by some of the issues @cb372 raised about Proto3 and their "everything is optional" policy, I have been thinking of a new design to accomodate this scenario, but also others like GraphQL in which sometimes you want to use a data type only to indicate that you want to query some field.

Essentially the idea is to move from the usual first-order data:

data Person = Person { name :: Text, age :: Int }

to a higher-kinded version in which every field is wrapped in a type constructor:

data Person f = Person { name :: f Text, age :: f Int }

Now we can indicate that every field is optional by using Person Maybe, or required by setting Person Id. As I said before, it also opens possibilities to describe things like "I want this field":

data Wanted   a = Wanted | NotWanted deriving Functor
data Obtained a = HereYouAre a | DidNotAskForIt deriving Functor

queryGraphQL :: Person Wanted -> Person Obtained

Of course, I am more than happy to execute the plan.

@kutyel kutyel added the enhancement New feature or request label Dec 9, 2019
serras added a commit that referenced this issue Dec 16, 2019
kutyel pushed a commit that referenced this issue Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants