
First I'd like to say that this is a very clever idea. Thanks for the
exposition. :-)
2008/3/21 Krzysztof Skrzętnicki
I'd like to write the following code:
instance (Ord a) => YOrd a where ycmp x y = case x `compare` y of LT -> (x,y) GT -> (y,x) EQ -> (x,y)
But i get an error "Undecidable instances" for any type [a]. Does anyone know the way to solve this?
This type of superclassing is not supported by the typeclass system. Finding systems where it is supported is a point of much lost sleep on my part. The typical way to solve this is rather disappointing: wrap it in a newtype: newtype YOrdWrap a = YOrdWrap { yordUnwrap :: a } instance (Ord a) => YOrd (YOrdWrap a) where ycmp (YOrdWrap x) (YOrdWrap y) = ycmpWrap x y And then apply the constructor whenever you want to use a "normal" type. Luke