[commit: ghc] master: Improve instanceCantMatch (6e618d7)
git at git.haskell.org
git at git.haskell.org
Fri Jul 24 11:31:08 UTC 2015
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/6e618d77d64255c32bef543a3f9635abce24a66d/ghc
>---------------------------------------------------------------
commit 6e618d77d64255c32bef543a3f9635abce24a66d
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Fri Jul 24 10:42:05 2015 +0100
Improve instanceCantMatch
When staring at instanceCantMatch I realised that it
was returning False (safe but inefficient) when it could
validly return True, on arguments like
[Nothing, Just Int]
[Just Bool, Just Bool]
This patch makes it a bit cleverer.
>---------------------------------------------------------------
6e618d77d64255c32bef543a3f9635abce24a66d
compiler/types/InstEnv.hs | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/compiler/types/InstEnv.hs b/compiler/types/InstEnv.hs
index e93d707..b8a3e6a 100644
--- a/compiler/types/InstEnv.hs
+++ b/compiler/types/InstEnv.hs
@@ -267,8 +267,12 @@ instanceCantMatch :: [Maybe Name] -> [Maybe Name] -> Bool
-- (instanceCantMatch tcs1 tcs2) returns True if tcs1 cannot
-- possibly be instantiated to actual, nor vice versa;
-- False is non-committal
-instanceCantMatch (Just t : ts) (Just a : as) = t/=a || instanceCantMatch ts as
-instanceCantMatch _ _ = False -- Safe
+instanceCantMatch (mt : ts) (ma : as) = itemCantMatch mt ma || instanceCantMatch ts as
+instanceCantMatch _ _ = False -- Safe
+
+itemCantMatch :: Maybe Name -> Maybe Name -> Bool
+itemCantMatch (Just t) (Just a) = t /= a
+itemCantMatch _ _ = False
{-
Note [When exactly is an instance decl an orphan?]
More information about the ghc-commits
mailing list