• Simon Peyton Jones's avatar
    Implement full co/contra-variant subsumption checking (fixes Trac #9569) · b6855422
    Simon Peyton Jones authored
    This is a pretty big patch, but which substantially iproves the subsumption
    check.  Trac #9569 was the presenting example, showing how type inference could
    depend rather delicately on eta expansion.  But there are other less exotic
    examples; see Note [Co/contra-variance of subsumption checking] in TcUnify.
    
    The driving change is to TcUnify.tcSubType.  But also
    
    * HsWrapper gets a new constructor WpFun, which behaves very like CoFun:
           if     wrap1 :: exp_arg <= act_arg
                  wrap2 :: act_res <= exp_res
           then   WpFun wrap1 wrap2 : (act_arg -> arg_res) <= (exp_arg -> exp_res)
    
    * I generalised TcExp.tcApp to call tcSubType on the result,
      rather than tcUnifyType.  I think this just makes it consistent
      with everything else, notably tcWrapResult.
    
    As usual I ended up doing some follow-on refactoring
    
    * AmbigOrigin is gone (in favour of TypeEqOrigin)
    * Combined BindPatSigCtxt and PatSigCxt into one
    * Improved a bit of error message generation
    b6855422
Match.lhs 40.6 KB