[Haskell-beginners] Type unions

Tobias Brandt tob.brandt at googlemail.com
Tue Dec 14 21:52:58 CET 2010


On 14 December 2010 21:44, Russ Abbott <russ.abbott at gmail.com> wrote:
> What's confusing is that
>
>
> data AorB = A | B
>
> compiles with error.
> That raises the question of what it really means!

You have to distinguish between type and value constructors.
On the left hand side of a data declaration you have
a type constructor (AorB) and possibly some type variables.
On the right hand side you have value constructors followed
by their arguments (types or type variables). E.g.:

data TypeConstr a b c = ValueConstr1 a b | ValueConstr2 c | ValueConstr3 Int

But in your example A and B were already declared as type
constructors, so they can't be used again as value constructors.
That's why you get an error. If you remove

data A = ...
and
data B = ...

then

data AorB = A | B

compiles.



More information about the Beginners mailing list