Thanks for the portable solution.
I'd also like to know how is the following different from
-XFlexibleInstances with [Char]? Stronger, weaker, same thing?
{-# OPTIONS -XTypeSynonymInstances #-}
class Stringable a where
toString :: a -> String
instance Stringable String where
toString = id
--A
On Wed, Oct 15, 2008 at 10:16 AM, Ryan Ingram <[EMAIL PROTECTED]> wrote:
> So, the Haskell98 solution to this is:
>
> class StringableList a where
> listToString :: [a] -> String
>
> -- now [a] is of the proper form; T = [], a is a type variable
> instance StringableList a => Stringable [a] where
> toString = listToString
>
> -- now to make an instance for Stringable [Char]
> -- we just make an instance for StringableList Char
> instance StringableList Char where
> listToString = id
>
> I think "FlexibleInstances" just makes the compiler jump through these
> hoops instead of you.
>
> -- ryan
>
> On Wed, Oct 15, 2008 at 3:20 AM, George Pollard <[EMAIL PROTECTED]> wrote:
>>
>> I'm a little confused. Why is this allowed:
>>
>>> data Blah = Blah
>>>
>>> instance Eq Blah where
>>> x == y = True
>>
>> But not this:
>>
>>> class Stringable a where
>>> toString :: a -> String
>>>
>>> instance Stringable [Char] where
>>> toString = id
>>
>> (Resulting in:)
>>
>>> Illegal instance declaration for `Stringable [Char]'
>>> (All instance types must be of the form (T a1 ... an)
>>> where a1 ... an are distinct type *variables*
>>> Use -XFlexibleInstances if you want to disable this.)
>>> In the instance declaration for `Stringable [Char]'
>>
>> 'Blah' isn't a type variable, is it? Is my brain just not working right
>> today?
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
> _______________________________________________
> Haskell-Cafe mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe