[Haskell-beginners] Help with a data type declaration

Karl Voelker karl at karlv.net
Tue Sep 29 15:27:59 UTC 2015


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


More information about the Beginners mailing list