<div dir="ltr">Thank you guys, very good descriptions given on my question. Together with your answers and the analogy of it being somewhat similar to something in C++ made me understand how it works. Again many thanks!<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 23, 2015 at 10:48 AM, Kim-Ee Yeoh <span dir="ltr"><<a href="mailto:ky3@atamo.com" target="_blank">ky3@atamo.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"><span class=""><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 23, 2015 at 2:51 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>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?</blockquote></div><br></div></span><div class="gmail_extra">In addition to the good answers already given, it helps to think of it this way:<br><br></div><div class="gmail_extra">Here's a list of Bools:<br><br></div><div class="gmail_extra">data ListBool = EmptyListBool | AddListBool Bool ListBool<br><br><div class="gmail_extra">Here's a list of Chars:<br><br></div>data ListChar = EmptyListChar | AddListChar Char ListChar<br><br><div class="gmail_extra">Here's a list of Ints:<br><br></div>data ListInt = EmptyListInt | AddListInt Int ListInt<br><br></div><div class="gmail_extra">Well just look at all that repetition!<br><br></div><div class="gmail_extra">Surely there must be a way to keep DRY and abstract over all that?<br><br></div><div class="gmail_extra">Let's see: what's common to all of the above? What stays the same? What changes? <br><br>Here's something that tries to express and separate out what's "fixed" and what's "insert type here":<br><br></div><div class="gmail_extra">data ListX = Empty | Add X ListX<br><br></div><div class="gmail_extra">We're close.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">That almost but doesn't quite work, because Haskell treats capital X as a concrete type, like Bool and Char and Int. <br><br>What we want is a type _variable_. And Haskell gives us that, if we use lower-case letters:<br><br></div><div class="gmail_extra">data List x = Empty | Add x (List x)<br><br></div><div class="gmail_extra">The parens is needed to distinguish against<br><br>data List x = Empty | Add x List x<br><br></div><div class="gmail_extra">which doesn't work for reasons you can probably guess.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Finally, it's convention to use type variables a b c and not x y z.<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div class="gmail_extra"><br clear="all"><div><div>-- Kim-Ee</div></div>
</div></font></span></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></div>