this repo has no description

Add a generalization test

authored by bernsteinbear.com and committed by

Max Bernstein 89e38bf9 97c98a0a

+6 -1
+6 -1
scrapscript.py
··· 4269 4269 return set().union(*(ftv_scheme(scheme) for scheme in ctx.values())) 4270 4270 4271 4271 # TODO(max): Freshen? 4272 - # TODO(max): Test with free type variable in the context 4273 4272 tyvars = ftv_ty(ty) - ftv_ctx(ctx) 4274 4273 return Forall([TyVar(name) for name in sorted(tyvars)], ty) 4275 4274 ··· 4670 4669 ) 4671 4670 ty = self.infer(expr, {"f": Forall([TyVar("a")], func_type(TyVar("a"), TyVar("a")))}) 4672 4671 self.assertTyEqual(ty, IntType) 4672 + 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"))) 4673 4678 4674 4679 def test_id(self) -> None: 4675 4680 expr = Function(Var("x"), Var("x"))