Commit 6e618d77 authored by Simon Peyton Jones's avatar Simon Peyton Jones

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.
parent d53d8089
......@@ -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?]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment