From 3e11768fcff710f84e02b0d6b3f07b7e2b559267 Mon Sep 17 00:00:00 2001 From: Paul Chiusano Date: Mon, 16 Jul 2018 12:07:19 -0400 Subject: [PATCH] generalizeExistentials ported --- .../src/Unison/Typechecker/Context2.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/parser-typechecker/src/Unison/Typechecker/Context2.hs b/parser-typechecker/src/Unison/Typechecker/Context2.hs index 132481d30..3d648498f 100644 --- a/parser-typechecker/src/Unison/Typechecker/Context2.hs +++ b/parser-typechecker/src/Unison/Typechecker/Context2.hs @@ -445,13 +445,13 @@ annotateLetRecBindings letrec = -- | Apply the context to the input type, then convert any unsolved existentials -- to universals. generalizeExistentials :: Var v => Context v loc -> Type v loc -> Type v loc -generalizeExistentials ctx t = error "todo" - -- foldr gen (apply ctx t) (unsolved ctx) - --where - -- gen e t = - -- if TypeVar.Existential e `ABT.isFreeIn` t - -- then Type.forall (TypeVar.Universal e) (ABT.subst (TypeVar.Existential e) (Type.universal e) t) - -- else t -- don't bother introducing a forall if type variable is unused +generalizeExistentials ctx t = + foldr gen (apply ctx t) (unsolved ctx) + where + gen e t = + if TypeVar.Existential e `ABT.isFreeIn` t + then Type.forall (loc t) (TypeVar.Universal e) (ABT.substInheritAnnotation (TypeVar.Existential e) (Type.universal e) t) + else t -- don't bother introducing a forall if type variable is unused -- | Check that under the given context, `e` has type `t`, -- updating the context in the process.