[Haskell] MPTCs and type inference

Iavor Diatchki iavor.diatchki at gmail.com
Mon Apr 25 18:45:45 EDT 2005


Hello,

On 4/25/05, Andrew Pimlott <andrew at pimlott.net> wrote:
> I appreciated your explanation, but can you also address (to the list)
> the last case given by the original poster?
> 
> > On 4/25/05, Andreas Rossberg <rossberg at ps.uni-sb.de> wrote:
> > > in particular, when I compare with the single parameter case:
> > >
> > >    class C a where fc :: a -> a -> ()
> > >
> > >    c1 x = let p = fc x in ()
> > >    c2 x = let p y = fc x y in ()
> > >
> > > where
> > >
> > >    c1 :: C a => a -> ()
> > >    c2 :: C a => a -> ()
> > >
> > > is inferred, as I would expect.

The inference steps for this case are much the same except, that the
inferred type for "p" now will be: "a -> ()", provided that we can
solve the constraint "C a".  Because we have assumptions about "a" in
the environment (namely it is mentioned in the type of the varible
"x") we cannot generalize the type of "p".  It therefore remains
monomorphic, and the constraint "C a" is propagated to the type of
"c2".

-Iavor


More information about the Haskell mailing list