Robustify lookupFamInstEnv, plus some refactoring
authorsimonpj@microsoft.com <unknown>
Thu, 15 Jan 2009 13:48:18 +0000 (13:48 +0000)
committersimonpj@microsoft.com <unknown>
Thu, 15 Jan 2009 13:48:18 +0000 (13:48 +0000)
commit027e6be20af2e59e2ec720042d23ef06d9a7d4c1
treea31358d8d4766eb456e3265c7c45f51b86df5ffd
parent27759873a8bd45c487a6e636f7a12c37e87f616f
Robustify lookupFamInstEnv, plus some refactoring

This patch deals with the following remark

     Suppose we have
            type family T a :: * -> *
            type instance T Int = []

     and now we encounter the type (T Int Bool).  If we call
     lookupFamInstEnv on (T Int Bool) we'll fail, because T has arity 1.
     Indeed, I *think* it's a precondition of lookupFamInstEnv that the
     supplied types exactly match the arity of the type function.  But
     that precondition is neither stated, nor is there an assertion to
     check it.

With this patch, lookupFamInstEnv can take "extra" type arguments in
the over-saturated case, and does the Right Thing.

There was a nearly-identical function lookupFamInstEnvUnify, which
required the precisely analogous change, so I took the opportunity
to combine the two into one function, so that bugs can be fixed in one
place.  This was a bit harder than I expected, but I think the result
is ok.  The conflict-decision function moves from FamInst to FamInstEnv.
Net lines code decreases, although there are more comments.
compiler/typecheck/FamInst.lhs
compiler/types/FamInstEnv.lhs