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

Sum types? #6

Open
Storyyeller opened this issue Aug 7, 2018 · 3 comments
Open

Sum types? #6

Storyyeller opened this issue Aug 7, 2018 · 3 comments

Comments

@Storyyeller
Copy link

Are sum types supported? If so, would it be possible to document the syntax used in the demo?

@stedolan
Copy link
Owner

The online demo doesn't have sum type support. There's some experimental support for sum types in the master branch, but the syntax isn't exactly stable. At the moment, it looks like this:

def map(f, list) = match list {
  case 'nil => 'nil
  case 'cons(hd = x, tl = xs) => 'cons(hd = f(x), tl = map(f, xs))
}

@LPTK
Copy link

LPTK commented Dec 13, 2018

Are they implemented as polymorphic variants? The quotation mark before the name seems reminiscent of them.

@stedolan
Copy link
Owner

Yes, they're similar to OCaml's polymorphic variants in that the variant names are just labels, not defined identifiers. Internally they use subtyping, rather than the row variables used by OCaml.

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

3 participants