mlsub icon indicating copy to clipboard operation
mlsub copied to clipboard

Sum types?

Open Storyyeller opened this issue 7 years ago • 3 comments

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

Storyyeller avatar Aug 07 '18 17:08 Storyyeller

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))
}

stedolan avatar Dec 13 '18 10:12 stedolan

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

LPTK avatar Dec 13 '18 13:12 LPTK

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.

stedolan avatar Dec 13 '18 13:12 stedolan