Extend defaulting plugin API to allow defaulting on multi-parameter type classes
Currently, the defaulting plugin API matches exactly the signature of the built-in defaulting mechanism, where each type variable occuring in the Wanteds
can be proposed to be defaulted to a priority list of types, one by one, with some extra constraints that need to hold after defaulting.
Since each new constraint is associated with a single defaultable type variable, this makes it impossible to propose defaults for multi-parameter typeclasses C a b
, or even constraints with multiple as-yet-unsolved type variablesC (T a b)
.
However, it would not take much to extend the plugin API to support this use case. I have a prototype implementation at cactus/ghc@b73d407b that changes the API to this:
data DefaultingProposal
= DefaultingProposal
{ deProposalTyVars :: [TcTyVar]
-- ^ The type variable to default.
, deProposalCandidates :: [[Type]]
-- ^ Candidate types to default the type variable to.
, deProposalCts :: [Ct]
-- ^ The constraints against which defaults are checked.
}
The types could be a bit tighter, because basically we want a rectangle of proposal candidates (all (equalLength deProposalTyVars) deProposalCandidates
), but I don't know how that's usually done in the GHC codebase so for the prototype this shall do.