Nguyen Phan Dung <[EMAIL PROTECTED]> writes:
>
> If I have the following declaration:
>
> class Soup where
> ...
>
> instance Soup String where
> ...
>
> instance Soup t => Soup [t] where
> ...
>
> This will lead to an error: "instance overlapping".
>
> Is there anyway to solve this?
> (I could not make an instance for Char)
One possibility is
> newtype MyString = MyString String
> instance Soup MyString where...
For another possibility let us assume:
> class Soup a where
> soupmethod :: souptype a
> instance Soup String where
> soupmethod = stringsoupmethod
> instance Soup t => Soup [t] where
> soupmethod = souplistfunctor (soupmethod :: souptype t)
A trick I am then using in these cases is the following:
> class Soup a where
> soupmethod :: Souptype a
> class SoupList a where
> souplistmethod :: Souptype [a]
> instance SoupList a => Soup [a] where
> soupmethod = souplistmethod
> instance SoupList Char where
> souplistmethod = stringsoupmethod
> instance SoupList t => SoupList [t] where
> souplistmethod = souplistfunctor souplistmethod
Maybe it does not give you all the power you want,
but in simple cases it serves me well.
Cheers,
Wolfram