[Haskell-beginners] Type unions

Hector Guilarte hectorg87 at gmail.com
Tue Dec 14 22:02:27 CET 2010


Tobias you replied at the same time I was answering, you did explained what
is happening,
however, you said something which isn't right. As I mentioned before, "Type
Constructors" and
"Value Constructors" are in different scopes, and so, their names can be
used again...

if you don't believe me, give it a try with this example. I didn't even try
it, but I asure you it
will compile without any trouble:

data A = C Int
data B = D Int

data AorB = A A | B B

Greeting,

Héctor Guilarte

On Tue, Dec 14, 2010 at 4:22 PM, Tobias Brandt <tob.brandt at googlemail.com>wrote:

> 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.
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20101214/f143a278/attachment.htm>


More information about the Beginners mailing list