scala/scala-dist — pull request #14 by namin (2012-02-23 15:26:00+00:00)
Title: Fix the Hindley-Milner Type Inference example in Scala by Example.

Bugs fixed:

1. The occurs check in mgu was looking for a String among a list of
TyVars, so it never found anything.

2. Also, the occurs check was looking at tyvars(u) not tyvars(su), so
it wasn't finding indirect cycles.

3. The generalization of type scheme was done in the unsubstituted
environment.

Test cases that now work:

For 1&2:
scala> testInfer.showType(Lam("x", App(Var("x"), Var("x"))))
// should fail, but caused infinite calls applying substitutions with cycles

For 3:
scala> testInfer.showType(Lam("f", Lam("x", Let("y", App(Var("f"), Var("x")), Var("y")))))
// should be (a->b)->a->b, but was (a->b)->a->c.