> Please, what is wrong here?
> 
> -------------------------------------------
> class Project a b where  prj :: b -> a -> b
> 
> data Pol a = Pol [(a,Int)] Char
> 
> instance Project (a,Int) (Pol a) where
>                                  prj (Pol _ c) (a,p) = Pol [(a,p)] c
> 
> f :: a -> Pol a -> Pol a
> f    a    g@(Pol ms _) =  prj g (head ms)
> 
> f' :: a -> Pol a -> Pol a
> f'    a    g     =  prj g (a,1)
> -------------------------------------------

The error message is

Foo.hs:14:
    Could not deduce `Project (a, t) (Pol a)'
        (arising from use of `prj' at Foo.hs:14)
        from the context: ()
    Probable cause: missing `Project (a, t) (Pol a)'
                    in type signature for `f''
                    or missing instance declaration for `Project (a, t) (Pol
a)'
    When checking the type signature(s) for `f''


The reason is that GHC doesn't know what type you want '1' to
be.  If you replaced '1' by '1::Int', it works fine.

You may say that, since there is only an instance for Project (a,Int)
if GHC wants to solve the constraint Project (a,t), it should bind t to Int.
That is possible (see Mark's thesis) but GHC doesn't do it.  Solving
class constraints never binds type variables.

Simon

Reply via email to