From f09bc7d19f2f87bf6540afd3240f3c274b8a4af2 Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Thu, 10 Apr 2008 11:28:12 +0000 Subject: [PATCH] Two improvements to boxy matching I can't quite remember what provoked these two changes, but they are in my tree. One improves boxy_match (which failed unnecessarily) One fixes boxy_lub (which was assymetrical) --- compiler/typecheck/TcUnify.lhs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/typecheck/TcUnify.lhs b/compiler/typecheck/TcUnify.lhs index d7399f5..709b7c4 100644 --- a/compiler/typecheck/TcUnify.lhs +++ b/compiler/typecheck/TcUnify.lhs @@ -616,6 +616,12 @@ boxy_match tmpl_tvs orig_tmpl_ty boxy_tvs orig_boxy_ty subst Nothing -> orig_boxy_ty Just ty -> ty `boxyLub` orig_boxy_ty + go _ (TyVarTy tv) | isMetaTyVar tv + = subst -- Don't fail if the template has more info than the target! + -- Otherwise, with tmpl_tvs = [a], matching (a -> Int) ~ (Bool -> beta) + -- would fail to instantiate 'a', because the meta-type-variable + -- beta is as yet un-filled-in + go _ _ = emptyTvSubst -- It's important to *fail* by returning the empty substitution -- Example: Tree a ~ Maybe Int -- We do not want to bind (a |-> Int) in pre-matching, because that can give very @@ -644,6 +650,10 @@ boxyLub orig_ty1 orig_ty2 | isTcTyVar tv1, isBoxyTyVar tv1 -- choose ty2 if ty2 is a box = orig_ty2 + go ty1 (TyVarTy tv2) -- Symmetrical case + | isTcTyVar tv2, isBoxyTyVar tv2 + = orig_ty1 + -- Look inside type synonyms, but only if the naive version fails go ty1 ty2 | Just ty1' <- tcView ty1 = go ty1' ty2 | Just ty2' <- tcView ty1 = go ty1 ty2' -- 1.7.10.4