[Haskell-beginners] Help with a data type declaration

Sumit Sahrawat, Maths & Computing, IIT (BHU) sumit.sahrawat.apm13 at iitbhu.ac.in
Tue Sep 29 15:35:47 UTC 2015


This Wikipedia article is a good read for getting the concepts right:
https://en.wikipedia.org/wiki/Algebraic_data_type

On 29 September 2015 at 20:57, Karl Voelker <karl at karlv.net> wrote:

> On Tue, Sep 29, 2015, at 07:10 AM, jamb at hinojosa.com wrote:
> > * "Tree" is the name of the new type.
> > * "Branch" and "Leaf" are the type constructors.
> > * What is "a" and "b"?
>
> "Tree" is not quite the name of a type. It is the name of a type
> constructor - in other words, it is a "type-level function". This also
> explains "a" and "b" - they are the parameters to the type constructor
> (which means they are "type variables").
>
> To get a type, you have to apply the type constructor. So, for example,
> "Tree Char Int" is a type.
>
> "Branch" and "Leaf" are not type constructors - they are *data*
> constructors.
>
> > * It seems to me that this type is kind of "recursively" defined but I
> > do not know exactly.
>
> Yes. It's recursive because a value of type "Tree a b" can be built up
> from other values of type "Tree a b" (if you use the "Branch"
> constructor).
>
> -Karl
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>



-- 
Regards

Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150929/8b17c3d1/attachment.html>


More information about the Beginners mailing list