[Haskell-cafe] Constructor classes implementation

Daniel Fischer daniel.is.fischer at web.de
Tue Feb 21 15:25:44 EST 2006


Am Montag, 20. Februar 2006 13:35 schrieb Daniel Fischer:
> >
> > Cheers,
> >
> > Sean
> >
> > p.s. If you find any bugs, please let me know.
>
> Re bugs:
>
> 1. printGamma [] would print an unmotivated " }", as witnessed by
> typeInf [] term14.
>
> 2. the case
> unify (ConT c) (AppT t1 t2)
> is missing.
>
and unifying a tyvar with itself fails. That probably doesn't occur in the 
inference-algorithm, but still...

> 3. too many shadowed bindings, this is always dangerous, I believe
>
> 4. I'm not sure, the datatypes are appropriate; as far as I know,
> expressions have a type and not a kind, which is what the use of the same
> Var type for Type and Exp entails.

and that led to an error: in generalise, we are interested in the free 
constructor-variables in the environment, not the term-variables, hence
-- Free variables in ...
-- ... schemes
fv_scheme :: Scheme -> [Var]
fv_scheme (Scheme vs ps ty)
     = nub (fv_preds ps ++ fv ty) \\ vs

-- ... environments
fv_gamma :: Gamma -> [Var]
fv_gamma gamma = nub (concatMap (fv_scheme . snd) gamma)

and not 
fv_gamma gamma = nub (map fst gamma)

>
> I have only just glimpsed at Jones' paper, so I don't yet see, what this
> type inference algorithm (quite nice, btw) has to do with constructor
> classes. If I still don't after reading it, I'll come back to ask.
>
I still don't see clearly. So you've implemented the type inference algorithm 
from Jones' paper, good. But is there any significance or gain, apart from it 
being a nice and interesting exercise?

Cheers,
Daniel

-- 

"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
	-- Blair P. Houghton



More information about the Haskell-Cafe mailing list