on master help sign in
Fix type constraints for case-expressions
commit175798f6d2419e2060d7dca6a7a91dc9c07e9ba2 authorEvan Czaplicki <info@elm-lang.org> dateTue 23 Jul 2013, 14:59 (13 years ago) parentf37e05a
2 files changed+8−7
compiler/Type/Constrain/Expression.hs+3−6 compiler/Type/Fragment.hs+5−1
compiler/Type/Constrain/Expression.hs+3−6
@@ -97,15 +97,12 @@ constrain env (L _ _ expr) tipe =
9797 ce <- constrain env e tipe
9898 return (cb /\ ce)
9999
100− Case e branches ->
100+ Case exp branches ->
101101 exists $ \t -> do
102− ce <- constrain env e t
102+ ce <- constrain env exp t
103103 let branch (p,e) = do
104104 fragment <- Pattern.constrain env p t
105− c <- constrain env e tipe
106− return $ ex (vars fragment)
107− (CLet [monoscheme (typeEnv fragment)]
108− (typeConstraint fragment /\ c))
105+ CLet [toScheme fragment] <$> constrain env e tipe
109106 CAnd . (:) ce <$> mapM branch branches
110107
111108 Data name exprs ->
compiler/Type/Fragment.hs+5−1
@@ -18,6 +18,10 @@ joinFragment f1 f2 = Fragment {
1818 typeEnv = Map.union (typeEnv f1) (typeEnv f2),
1919 vars = vars f1 ++ vars f2,
2020 typeConstraint = typeConstraint f1 /\ typeConstraint f2
21− }
21+}
2222
2323joinFragments = List.foldl' (flip joinFragment) emptyFragment
24+
25+
26+toScheme fragment =
27+ Scheme [] (vars fragment) (typeConstraint fragment) (typeEnv fragment)