<div dir="ltr">What you wrote is equivalent to the following pseudo-haskell.<br><br><b>List</b> takes a type and returns a new type, which represents a list of elements of that type in this case. Thus <b>List</b> is a <b>type-constructor</b>.<div>It has two data-constructors, i.e. there are two ways to create elements of the type <b>List a</b>, for any type a.</div><div><br><div><font face="monospace, monospace">-- 'Empty' is a value of type 'List a', for all types 'a'. This is one possible way to construct elements of type 'List a'.</font></div><div><font face="monospace, monospace">Empty :: List a</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">-- 'Add' is a function that takes an element of type 'a', and a 'List a', and constructs a 'List a' out of them.</font></div><div><font face="monospace, monospace">Add :: a -> List a -> List a</font></div></div><div><font face="monospace, monospace"><br></font></div>Using the GHC extension, <b>GADTs</b>, it is possible to write code that directly reflects this structure. Although that is considered an advanced feature of the language.<div><br></div><div><font face="monospace, monospace">{-# LANGUAGE GADTs #-}</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">data List a where</font></div><div><font face="monospace, monospace"> Empty :: List a</font></div><div><font face="monospace, monospace"> Add :: a -> List a -> List a</font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 23 September 2015 at 13:21, goforgit . <span dir="ltr"><<a href="mailto:teztingit@gmail.com" target="_blank">teztingit@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I have a follow up question, I hope it's alright.<br><br>What about the following?<br><span style="font-family:monospace,monospace"><br>data List a = Empty | Add a (List a)</span><br><br></div>What does the a mean and why is it possible to put it there?<div><div class="h5"><br><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 22, 2015 at 4:54 PM, goforgit . <span dir="ltr"><<a href="mailto:teztingit@gmail.com" target="_blank">teztingit@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks Brandon, that cleared things up!<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Mon, Sep 21, 2015 at 8:39 PM, Brandon Allbery <span dir="ltr"><<a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><div class="gmail_extra"><span><br><div class="gmail_quote">On Mon, Sep 21, 2015 at 2:23 PM, goforgit . <span dir="ltr"><<a href="mailto:teztingit@gmail.com" target="_blank">teztingit@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>Could someone explain to me the difference between the following?<br><br></div><span style="font-family:monospace,monospace">data Atype = Numeric Integer | A | B C<br></span><span style="font-family:arial,helvetica,sans-serif"><br></span></div><span style="font-family:arial,helvetica,sans-serif">and</span><span style="font-family:monospace,monospace"><br><br>data Atype = Integer | A | B C</span><br></blockquote></div><div class="gmail_extra"><br></div></span>The second one is an enumeration with three values: "Integer" (which is *not* an integer, nor does it contain one), "A", and "B" which as written there takes a value of some unspecified type C as a parameter.</div><div class="gmail_extra">The first one is a enumeration with three values: "Numeric" which takes an Integer as a parameter, "A", and "B" which takes a value of some unspecified type C as a parameter.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Note that the "Integer" in the second one has *nothing whatsoever* to do with the *type* Integer.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Remember that you must always provide a data constructor with "data"; you cannot simply say "data MyInt = Integer" to "wrap" an Integer, because you have not said what to wrap it *in*. (You may have intended to create a type alias, though; that would be "type", not "data".) A "data" always requires a data constructor name, so the compiler can tell when you are talking about a value of that type by looking for the constructor.<span><font color="#888888"><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div>brandon s allbery kf8nh sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a> <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div><div>unix, openafs, kerberos, infrastructure, xmonad <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div></div>
</font></span></div></div>
<br></div></div>_______________________________________________<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" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div></div></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" rel="noreferrer" 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>