I'm pretty sure everyone is familiar with generic methods of the form:
T DoSomething<T>(T item)
This function is also called parametrically polymorphic (PP), specifically rank-1 PP.
Let's say this method can be represented using a function object of the form:
<T> : T -> T
That is, <T>
means it takes one type parameter, and T -> T
means that it takes one parameter of type T
and returns a value of the same type.
Then the following would be a rank-2 PP function:
(<T> : T -> T) -> int
The function takes no type parameters itself, but takes a function which takes a type parameter. You can continue this iteratively, making the nesting deeper and deeper, getting PP of higher and higher rank.
This feature is really rare among programming languages. Even Haskell doesn't allow it by default.
Is it useful? Can it describe behaviors that are difficult to describe otherwise?
Also, what does it mean for something to be impredicative? (in this context)
let sdff = (g : (f : <T> (e : T) => void) => void) => {}