
1 Dec
2009
1 Dec
'09
4:40 p.m.
Hi Patrick As you guessed, adding UndecidableInstances pragma would make it work. Loosely speaking, the type of your instance 'contains' all the types that the class can use anyway. Hopefully, someone more learned than me will give a proper definition and add an explanation of the Paterson Conditions. http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class-extension... But why not just a function: toInt :: Integral a => a -> Int toInt = fromIntegral Of course just a function won't be ideal if you were wanting to have a special instance say for Integer and all other instances to use the general version. There's more to say about this in the context of Generics, but that's a somewhat advanced topic... Best wishes Stephen