O'Haskell OOP Polymorphic Functions

Ashley Yakeley ashley@semantic.org
Tue, 16 Jan 2001 14:52:35 -0800


At 2001-01-16 14:36, Tom Pledger wrote:

>Here's a similar example using type-substitution overlapping:
>
>    instance               TheValue Char      where ...
>    instance Monad m    => TheValue (m Char)  where ...
>    instance TheValue a => TheValue (Maybe a) where ...
>
>    trouble = theValue (Just 'b')

Apparently this is not good Haskell syntax. I tried compiling this in 
Hugs:

class TheValue a where theValue :: a -> Int
instance               TheValue Char      where theValue _ = 0
instance (Monad m) => TheValue (m Char)  where theValue _ = 1        -- 
error here
instance (TheValue a) => TheValue (Maybe a) where theValue _ = 2

trouble = theValue (Just 'b')

I got a syntax error:
(line 3): syntax error in instance head (variable expected)


-- 
Ashley Yakeley, Seattle WA