[Haskell-cafe] Type constraints for class instances

Bas van Dijk v.dijk.bas at gmail.com
Fri Mar 21 04:43:35 EDT 2008


2008/3/21 Krzysztof Skrzętnicki <gtener at gmail.com>:
>  ...
>  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?

The module compiles fine when you add the following pragma's to your module:

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}

See:
http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class-extensions.html#instance-rules
http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class-extensions.html#undecidable-instances

regards,

Bas


More information about the Haskell-Cafe mailing list