<div dir="ltr"><div>I can't understand what you mean by those colons in the second definition of Person. If you're thinking of type signatures, then that doesn't work in haskell.</div><div>In an ADT, you give names to possible values. So "Name String" will work whereas "Name : String" won't work.</div><div><br></div><div><font face="monospace, monospace">data Person = Name String</font></div><div><font face="monospace, monospace"> | Age Integer</font></div><div><font face="monospace, monospace"> | FavThing String</font></div><div><font face="monospace, monospace"><br></font></div>means that Person can be <b><i>one of</i></b> these things (which is not what you want).<div><br></div><div>What you want is possible with record syntax. He'll detail it later I think.</div><div>If you're interested in learning about it beforehand, look it up in the haskell wikibook (another great haskell resource).</div><div><br></div><div>More about ADTs in general: <a href="http://en.wikibooks.org/wiki/Haskell/Type_declarations#data_and_constructor_functions">http://en.wikibooks.org/wiki/Haskell/Type_declarations#data_and_constructor_functions</a></div><div>The link to the specific section: <a href="http://en.wikibooks.org/wiki/Haskell/More_on_datatypes#Named_Fields_.28Record_Syntax.29">http://en.wikibooks.org/wiki/Haskell/More_on_datatypes#Named_Fields_.28Record_Syntax.29</a></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 19 February 2015 at 21:58, Roelof Wobben <span dir="ltr"><<a href="mailto:r.wobben@home.nl" target="_blank">r.wobben@home.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Hello, <br>
<br>
Im reading chapter 2 of the CIS 194 course about enumaratuin.<br>
<br>
Now they give this example : <br>
<br>
<pre><code><span>-- Store a person's name, age, and favourite Thing.</span>
<span>data</span> <span>Person</span> <span>=</span> <span>Person</span> <span>String</span> <span>Int</span> <span>Thing</span>
<span>deriving</span> <span>Show</span>
<span>brent ::</span> <span>Person</span>
brent <span>=</span> <span>Person</span> <span>"Brent"</span> <span>31</span> <span>SealingWax</span>
<span>stan ::</span> <span>Person</span>
stan <span>=</span> <span>Person</span> <span>"Stan"</span> <span>94</span> <span>Cabbage</span>
<span>getAge ::</span> <span>Person</span> <span>-></span> <span>Int</span>
getAge (<span>Person</span> _ a _) <span>=</span> a
I understand how this works.
But I wonder if there is no "better" way to get the Age.
Is it now wise to make a person data like this :
data Person = Name : String
| Age : Integer
| FavThing : String
And if so , how can I get the age then ?
Roelof
</code></pre>
<br>
</div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Regards</div><div dir="ltr"><div><br></div><div>Sumit Sahrawat</div></div></div></div></div></div></div>
</div>