request : intelligent implicit generalization #14506
Labels
kind: feature
New user-facing feature request or implementation.
part: typeclasses
The typeclass mechanism.
The documetation of backquote implicit generalization states:
It would be nice to have a similar mechanism that does instance search first, deciding to generalize only those typeclass binder requirements that cannot be fulfilled in the current context, such as by preceding arguments.
Suppose we have 3 standalone typeclasses, 2 dependent typeclasses and a function definition that uses those 2:
The problem is with conveniently specifying the arglist of
f
. Saying:Definition f `{C4,C5} := ...
means that the instances for C4 and C5 do not share the instance of C1, which may cause issues within the definition of f. Saying instead:
Definition f `{C4,!C5} := ...
does not work because C3 is missing, as C5 is not generalized over at all. Reversing the order of C4 and C5 does not help because it produces a symmetric problem involving C2 instead of C3.
Currently, there is no way to accomplish this without explicitly naming C3 (or C2 if the order is reversed).
This request is for some convenient mechanism to implicitly generalize C5 over what can't be found by typeclass search at the point where the C5 argument appears, in this case only C3 because C1 is already provided by the generalization of C4.
The text was updated successfully, but these errors were encountered: