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

MR K P SCHUPKE k.schupke at imperial.ac.uk
Wed Mar 31 13:36:28 EST 2004


>This syntax would also have the advantage that you can apply different
>contexts to different constructors.

Er, you can already do that as I just pointed out:

data (Ord a,Num b) => Either a b = Left a | Right b 

Note that to constrain the same type variable differently
for different constructors would be a type error. In other
words this:

	data Either a = 
		Num a => Left a
		Ord a => Right a

Is not valid, because (forall a . Num a) is not the same
type as (forall a . Ord a). So infact the current way
of writing it as

	data (Num a) => Either a = Left a | Right a

Is better because it does not allow you to make that mistake.

	Regards,
	Keean.


More information about the Haskell-Cafe mailing list