Erlang is a dynamically typed language, so you don't really declare data types. You can just use the data representation you choose. <br>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".<br>
<br>The form GADTs usually take is tuples-with-fixed-atoms-as-first-element (or just atoms for variants that don't contain data).<br>Haskell GADTs like<br><div dir="ltr" style="text-align:left"><div dir="ltr" style="text-align:left">
<pre class="source-haskell"><span class="kw1"> data</span> <span class="kw4">Either</span> a b <span class="sy0">=</span> Left a <span class="sy0">|</span> Right b<br></pre></div><pre class="source-haskell"><span class="kw1"> data</span> Maybe a <span class="sy0">=</span> Some a <span class="sy0">|</span> None<br>
</pre></div>would be described in Erlang as<br><br> -type either(A,B) :: {left,A} | {right,B}.<br> -type maybe(A) :: {some,A} | none.<br><br>and used in function specs as<br><br> -spec swap_left_and_right/1 :: (either(A,B)) -> either(B,A).<br>
-spec retract_left/1 :: (either(A,B)) -> maybe(A).<br><br>See also, for instance,<br> <a href="http://learnyousomeerlang.com/types-or-lack-thereof">http://learnyousomeerlang.com/types-or-lack-thereof</a><br>and<br>
<a href="http://learnyousomeerlang.com/dialyzer">http://learnyousomeerlang.com/dialyzer</a><br><br><div class="gmail_quote">2013/2/11 Andrew Pennebaker <span dir="ltr"><<a href="mailto:andrew.pennebaker@gmail.com" target="_blank">andrew.pennebaker@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Does Erlang have anything like Haskell GADTs? How are structured data types declared in Erlang?<span class="HOEnZb"><font color="#888888"><br clear="all">
<div><br></div>-- <br><div></div>Cheers,<div><br></div><div>Andrew Pennebaker</div><div><a href="http://www.yellosoft.us" target="_blank">www.yellosoft.us</a></div>
</font></span></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br>