Jump to content

Compound data type: Difference between revisions

(→‎{{header|Erlang}}: added implementation)
Line 355:
=={{header|Ela}}==
 
Ela supports algebraic types:
Ela supports variant type (similar to polymorphic variants in OCaml). No definition for variants is required:
 
<lang ela>pointtype x yMaybe = PointNone | xSome ya</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>typeopentype foobarSeveral = 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}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.