[Haskell-cafe] Adding Ord constraint to instance Monad Set?

Wolfgang Jeltsch wolfgang at jeltsch.net
Wed Mar 31 15:56:05 EST 2004

Am Mittwoch, 31. März 2004 15:42 schrieb MR K P SCHUPKE:
> > 	data Either a =3D
> > 		Num a =3D> Left a
> > 		Ord a =3D> Right a
> This is a mistake because the same variable is being constrained in
> two different ways. The only way both constrains can be satisfied
> is if a is both in Num and Ord. This can be written:
> 	data (Num a,Ord a) => Either a = Left a | Right a
> Which makes it a lot clearer that the constaints apply to both
> the Left and Right constructor.
> You have to remember that a is a polymorphic variable... now the
> first line [Num a => Left a] says that a has the type (forall a . Num a)
> but the second line [Ord a => Right a] says a has the type (forall a . Ord
> a) These are not the same type, so when they are combined (remember a
> scopes over the whole type definition) there is a type error because:
> 	(forall a . Ord a) is not the same as (forall a . Num a)
> 	Regards,
> 	Keean.

My intention was that the context before a data constructor shall mean that 
the variable (a) shall be constrained only in the type of the constructor 
function, not in the type definition.

In a way, even in Haskell 98, (a) is only constrained in the type of the 
constructor function.  Saying "a is constricted for the whole type 
definition." would suggest that Either can only be applied to Ord instances 
which isn't true as we have seen.


More information about the Haskell-Cafe mailing list