<div dir="ltr">Yes, "age p" gives the age of the person represented by "p".</div><div class="gmail_extra"><br><div class="gmail_quote">On 19 February 2015 at 22:50, 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">
<div>Oke, I read that part. <br>
<br>
Then I would be age p = ag <br>
<br>
Roelof<br>
<br>
<br>
<br>
Sumit Sahrawat, Maths & Computing, IIT (BHU) schreef op
19-2-2015 om 18:03:<br>
</div><div><div class="h5">
<blockquote type="cite">
<div dir="ltr"><font face="monospace, monospace">When you use
record syntax, accessors are automatically created for you.
So,</font>
<div><font face="monospace, monospace"><br>
</font></div>
<div><font face="monospace, monospace">data Person = Person {<br>
</font></div>
<div><font face="monospace, monospace"> 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"> }</font></div>
<div><font face="monospace, monospace"><br>
</font></div>
<font face="monospace, monospace">means that name, age and
favThing are functions that do exactly what you want:</font>
<div><font face="monospace, monospace"><br>
</font>
<div><font face="monospace, monospace"> name :: Person
-> String</font></div>
<div><font face="monospace, monospace"> age :: Person
-> Integer</font></div>
<div><font face="monospace, monospace"> favThing :: Person
-> String</font></div>
<div><font face="monospace, monospace"><br>
</font></div>
<div><font face="monospace, monospace">So you just need to
call age on a Person value to get the age.</font></div>
<div><font face="monospace, monospace">Due to this
functionality, the names in record syntax can not start
with an uppercase letter.</font></div>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On 19 February 2015 at 22:27, 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">
<div>Thanks, <br>
<br>
That is not what I mean , <br>
<br>
I mean this : <br>
<span> <br>
<span>data</span> Person <span>=</span> Person<br>
<span>{</span> name <span>::</span> <span>String</span>
,<br>
</span> Age <span>::</span> Integer<span></span>
, <br>
FavThing <span>::</span> <span>String</span> <span></span>
<span>}</span> <br>
<br>
<br>
and i want to get the Age I could do this : <br>
<br>
getAge <span>(Person</span> <span>{age</span> <span>=</span>
ag})<span></span> <span>=</span> ag<br>
<br>
Roelof<br>
<br>
<span></span> <br>
Sumit Sahrawat, Maths & Computing, IIT (BHU) schreef
op 19-2-2015 om 17:37:<br>
</div>
<div>
<div>
<blockquote type="cite">
<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" target="_blank">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" target="_blank">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" target="_blank">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>
<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>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
Beginners mailing list
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>
</pre>
</blockquote>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div>
<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>
</blockquote>
<br>
</div></div></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>