[Haskell-beginners] Typeclass question
Stephen Tetley
stephen.tetley at gmail.com
Tue Dec 1 11:40:21 EST 2009
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-extensions.html#undecidable-instances
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
More information about the Beginners
mailing list