Considering
data Foo = FooString String … class Fooable a where --(is this a good way to name this?) toFoo :: a -> Foo
I want to make a String instance Fooable :
instance Fooable String where toFoo = FooString
GHC then complains:
Illegal instance declaration for `Fooable String' (All instance types must be of the form (T t1 ... tn) where T is not a synonym. Use -XTypeSynonymInstances if you want to disable this.) In the instance declaration for `Fooable String'
If instead I use [Char] :
instance Fooable [Char] where toFoo = FooString
GHC complains:
Illegal instance declaration for `Fooable [Char]' (All instance types must be of the form (T a1 ... an) where a1 ... an are type *variables*, and each type variable appears at most once in the instance head. Use -XFlexibleInstances if you want to disable this.) In the instance declaration for `Fooable [Char]'
Question
- Why can't I create a String and an instance of a class?
- The GHC seems to want me to get away with adding an extra flag. Is that a good idea?
type-systems haskell ghc typeclass
John F. Miller May 9 '11 at 19:45 2011-05-09 19:45
source share