Skip to content

Commit 89e38bf

Browse files
committed
Add a generalization test
1 parent 97c98a0 commit 89e38bf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

scrapscript.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4269,7 +4269,6 @@ def ftv_ctx(ctx: Context) -> set[str]:
42694269
return set().union(*(ftv_scheme(scheme) for scheme in ctx.values()))
42704270

42714271
# TODO(max): Freshen?
4272-
# TODO(max): Test with free type variable in the context
42734272
tyvars = ftv_ty(ty) - ftv_ctx(ctx)
42744273
return Forall([TyVar(name) for name in sorted(tyvars)], ty)
42754274

@@ -4671,6 +4670,12 @@ def test_apply_polytype_to_different_types(self) -> None:
46714670
ty = self.infer(expr, {"f": Forall([TyVar("a")], func_type(TyVar("a"), TyVar("a")))})
46724671
self.assertTyEqual(ty, IntType)
46734672

4673+
def test_generalization(self) -> None:
4674+
# From https://okmij.org/ftp/ML/generalization.html
4675+
expr = parse(tokenize("x -> (y . y = x)"))
4676+
ty = self.infer(expr, {})
4677+
self.assertTyEqual(ty, func_type(TyVar("a"), TyVar("a")))
4678+
46744679
def test_id(self) -> None:
46754680
expr = Function(Var("x"), Var("x"))
46764681
ty = self.infer(expr, {})

0 commit comments

Comments
 (0)