[erlang-questions] GADTs / polymorphic data types?

Erik Søe Sørensen eriksoe@REDACTED
Wed Feb 13 02:40:28 CET 2013


Erlang is a dynamically typed language, so you don't really declare data
types. You can just use the data representation you choose.
That is: you may declare types using "-type" and "-spec" - but the compiler
and runtime as such don't care about such declarations; they are for the
separate type checker "dialyzer".

The form GADTs usually take is tuples-with-fixed-atoms-as-first-element (or
just atoms for variants that don't contain data).
Haskell GADTs like

    data Either a b = Left a | Right b

    data Maybe a = Some a | None

would be described in Erlang as

    -type either(A,B) :: {left,A} | {right,B}.
    -type maybe(A) :: {some,A} | none.

and used in function specs as

    -spec swap_left_and_right/1 :: (either(A,B)) -> either(B,A).
    -spec retract_left/1 :: (either(A,B)) -> maybe(A).

See also, for instance,
   http://learnyousomeerlang.com/types-or-lack-thereof
and
   http://learnyousomeerlang.com/dialyzer

2013/2/11 Andrew Pennebaker <andrew.pennebaker@REDACTED>

> Does Erlang have anything like Haskell GADTs? How are structured data
> types declared in Erlang?
>
> --
> Cheers,
>
> Andrew Pennebaker
> www.yellosoft.us
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130213/0a94c122/attachment.htm>


More information about the erlang-questions mailing list