Say that I want to encode cons as:
def cons(a, b):
return lambda f : f(a, b)
I would like to add typing to the cons above. The obvious typing would be:
T = TypeVar('T')
U = TypeVar('U')
V = TypeVar('V')
def cons(a: T, b: U) -> Callable[[Callable[[T, U], V]], V]:
return lambda f : f(a, b)
However, the above doesn't type check in pyre which gives:
cons.py:7:24 Invalid type variable [34]: The type variable `Variable[V]` isn't present in the function's parameters.
I assume that what I need is a universal quantification of the return type of the function.
Is there a way to express this in the Python type-system?