Here I mean only simple typed Lambda calculus / Combinatory logic.
Notation: Combinatory logic terms: $F, X_i, Y_i$. Term application: $(F*X_1)$. Type variables $x_i,y_i$. Type assignment: $X:x_i$.
There is well known principal-type algorithm. For a given term M we can derive the most general type (if it exists)
For example: $K:a\rightarrow(b\rightarrow a)$, $KK:c\rightarrow(a\rightarrow(b\rightarrow a))$, $SII$:does not have a type.
I am interested in the following problem:
Hidden term: $F:x\rightarrow y$
Given: $\{(X_1:x_1, Y_1=(F*X_1):y_1), (X_2:x_2, Y2=(F*X_2):y_2)\}$, all pairs come in normal reduced form.
How to infer a type of hidden term $F$? Such that $(F:x\rightarrow y* X_1:x_1):y_1$ and $(F:x\rightarrow y* X_2:x_2):y_2$
For example:
There is hidden term $F$, $F=S:(a\rightarrow (b\rightarrow c))\rightarrow ((a\rightarrow b)\rightarrow (a\rightarrow c)))$
We have access only to 2 (input, output) pairs:
$X_1:x_1 = K:(a\rightarrow (b\rightarrow a))$
$Y_1:y_1 = F * X_1 = SK:(a\rightarrow b)\rightarrow (a\rightarrow a))$
$X_2:x_2 = S:((a\rightarrow (b\rightarrow c))\rightarrow ((a\rightarrow b)\rightarrow (a\rightarrow c)))$
$Y_2:y_2 = F * X_2 = SS:(((a\rightarrow (b\rightarrow c))\rightarrow (a\rightarrow b))\rightarrow ((a\rightarrow (b\rightarrow c))\rightarrow (a\rightarrow c)))$
How to infer a type $(x\rightarrow y)$ of hidden term $F$, such that:
$(F:x\rightarrow y * X_1:(a\rightarrow (b\rightarrow a))) : (a\rightarrow b)\rightarrow (a\rightarrow a))$
$(F:x\rightarrow y * X_2:((a\rightarrow (b\rightarrow c))\rightarrow ((a\rightarrow b)\rightarrow (a\rightarrow c))))
: (((a\rightarrow (b\rightarrow c))\rightarrow (a\rightarrow b))\rightarrow ((a\rightarrow (b\rightarrow c))\rightarrow (a\rightarrow c)))$
In this particular example, the answer is: $x\rightarrow y = (a\rightarrow (b\rightarrow c))\rightarrow ((a\rightarrow b)\rightarrow (a\rightarrow c)))$
It is easy to verify. Given this type and type of $X_i$, the principle type algorithm will derive $Y_i$ in both cases.
It is like backward type inference. For a set of $\{(input_1, output_1),..\}$ derive a most general type of a function.
Maybe there is a name for this problem that was already implemented in some programming languages?