
TP
Hi,
I struggle with a dummy example using a multi-parameter typeclass containing a default implementation for a function:
--------------------------------------- {-# LANGUAGE MultiParamTypeClasses #-}
class Foo a b where
bar :: a -> Int
The problem is in this declaration, which does not mention the type "b". This makes it impossible for the compiler to infer which instance to use when "bar" is used. This is what the compiler is trying to tell you when it says "The type variable `b1' is ambiguous". As far as I know, you'd need to do something like this to accomplish what you are after, {-# LANGUAGE MultiParamTypeClasses, DefaultSignatures #-} class Bar a where bar :: a -> Int class FooBar a b where foobar :: a -> b -> Int default foobar :: Bar a => a -> b -> Int foobar avalue bvalue = bar avalue instance Bar Int where bar i = 5 instance FooBar Int Int main = do print $ bar (4::Int) print $ foobar (5::Int) (2::Int) Cheers, - Ben