[Haskell-cafe] instance of String illegal

Adam Hupp adam at hupp.org
Thu Sep 28 22:37:19 EDT 2006


I am trying to create an instance of a class for String types.  I have
the following:

class Foo a where
    mkFoo :: a -> String

instance Foo String where
    mkFoo x = x

and receive the following error:

test.hs:9:0:
    Illegal instance declaration for `Foo String'
        (The instance type must be of form (T a b c)
         where T is not a synonym, and a,b,c are distinct type
    variables)
    In the instance declaration for `Foo String'
Failed, modules loaded: none.

I see that in general I am not able to create an instance of a class for any
type [a], where a is a specific type.

I can work around it by wrapping my Strings in some other data type
but I'd like to understand why it's not possible.  Any insight would
be appreciated.

-Adam



More information about the Haskell-Cafe mailing list