mlsub
mlsub copied to clipboard
Sum types?
Are sum types supported? If so, would it be possible to document the syntax used in the demo?
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))
}
Are they implemented as polymorphic variants? The quotation mark before the name seems reminiscent of them.
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.