[Haskell-cafe] Type constraints for class instances

Krzysztof Skrzętnicki gtener at gmail.com
Fri Mar 21 20:15:40 EDT 2008


It compiles, but it doesn't work when i try to use it on lists. There
are some bugs in that code, but I need some time to fix it.

2008/3/21 Bas van Dijk <v.dijk.bas at gmail.com>:
> 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