[Haskell-cafe] Having trouble with instance context

Kurt Stutsman kstutsman at gmail.com
Wed Feb 23 03:10:58 CET 2011


I am trying to create an instance of a class for data types deriving 
from Enum. When I try to specify this through a context on the instance 
definition, I get an error. When I do something similar with a function, 
it seems to work fine. Why does the instance not work?

{------------ Example: ---------------}

class Test t where
    func :: t -> Int

-- This instance does not compile
instance (Enum e) => Test e where
    func x = fromEnum x

-- This function does work
newfunc :: (Enum e) => e -> Int
newfunc x = fromEnum x


Thanks,
Kurt



More information about the Haskell-Cafe mailing list