Compound data type: Difference between revisions

Content added Content deleted
(→‎{{header|Erlang}}: added implementation)
Line 355: Line 355:
=={{header|Ela}}==
=={{header|Ela}}==


Ela supports algebraic types:
Ela supports variant type (similar to polymorphic variants in OCaml). No definition for variants is required:


<lang ela>point x y = Point x y</lang>
<lang ela>type Maybe = None | Some a</lang>


Except of regular algebraic types, Ela also provides a support for open algebraic types - which can be extended any time with new constructors:
Variants can also be used when constructing user types. A user type declaration in Ela can have one more constructor functions or constants:


<lang ela>type foobar
<lang ela>opentype Several = One | Two | Three
where foo x = Foo x
bar x = Bar x</lang>


//Add new constructor to an existing type
In the code sample above we introduce a custom type foobar with two constructor functions that return variants Foo and Bar. Both of them belong to foobar type.
data Several = Four</lang>


=={{header|Erlang}}==
=={{header|Erlang}}==