First, there is an even simpler case that won't work:
class A a where
foo :: a -> b
The question is what is 'b'. According to this b can be anything not something specific. If you want 'b' to be something specific in must appear as part of the type class declaration.
To do what you want to do, you could use the extension MultiParamTypeClasses.
class A a
class (A a, A b) => B a b where
foo :: a -> b
instance A Int
instance B Int Int where
foo = id
Second, Haskell does not by default allow for type synonyms in instance declarations. String is a type synonym of [Char]. If you want to use String in instance declarations use the extension TypeSynonymInstances and FlexibleInstances.
instance A String
instance A String String where
foo = id
James