[Haskell-beginners] Problems with typeclasses instances

ARJANEN Loïc Jean David arjanen.loic at gmail.com
Wed Jul 13 14:56:33 CEST 2011


I have the following problem with typeclasses : I have created a type
class in a manner similar to the following

module Dummy where
import Char
class (Show t) => Dummy t where
    kite :: t -> t
instance (Dummy t) => Dummy [t] where
    kite = reverse
instance Dummy String where
    kite = map toUpper

And use it thus :

import Dummy
main :: IO ()
main = do
    print.kite $ "Rest in peace"

If I compile without any option, I get as expected an error because of
the type synonym instance. If I remove the instance for String, I also
get as expected an error because Char is not an instance of Dummy. But
if I add (as suggested in the first error message) the GHC's option
-XTypeSynonymInstances, I get an error because of overlapping
instances, even if Char is still not an instance of Dummy and I don't
see how String could be eligible for the (Dummy t) => Dummy [t]
instance...

Thanks in advance for your help,
ARJANEN Loic.



More information about the Beginners mailing list