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

Wolfgang Jeltsch wolfgang at jeltsch.net
Wed Mar 31 15:06:40 EST 2004

Am Mittwoch, 31. März 2004 14:36 schrieb MR K P SCHUPKE:
> >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.

I cannot see what the mistake is.  What's wrong with having one data 
constructor of type
    (Num a) => a -> Either a
and another of type
    (Ord a) => a -> Either a?
Both are completely independent.

So the current way of writing would not prevent me from making a mistake but 
instead means the lack of a useful feature.


More information about the Haskell-Cafe mailing list