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

Add support for variants #2

Open
gabejohnson opened this issue Apr 27, 2018 · 0 comments
Open

Add support for variants #2

gabejohnson opened this issue Apr 27, 2018 · 0 comments

Comments

@gabejohnson
Copy link
Owner

gabejohnson commented Apr 27, 2018

In place of traditional sum and product types, the plan is to only support polymorphic records and variants. The records are already in place, so that just leaves the variants.

In order to support variant elimination, we need a way to handle the cases. This could be done w/ if or switch statements, but I'd like to use babel/babel#7633 if it's not too much work.

Variant types would be declared as follow (via the Flow type AST):

type Either<l,r> = {Left: l} | {Right: r};

let
either: <l,r,a>(l => a) => (r => a) => Either<l,r> => a;
either = f => g => e => match(e) {
  ({Left: l}) => f(l),
  ({Right: r}) => g(r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant