In section 23.8 of his book Types and Programming Languages, Benjamin C. Pierce writes the following:
Another well-studied restriction of System F is rank-2 polymorphism, introduced by Leivant (1983) [...]. A type is said to be of rank 2 if no path from its root to a ∀ quantifier passes to the left of 2 or more arrows, when the type is drawn as a tree. [...] In the rank-2 system, all types are restricted to be of rank 2. This system is slightly more powerful than the prenex (ML) fragment, in the sense that it can assign types to more untyped lambda-terms.
Kfoury and Tiuryn (1990) proved that the complexity of type reconstruction for the rank-2 fragment of System F is identical to that of ML (i.e, DExptime-complete). Kfoury and Wells (1999) gave the first correct type reconstruction algorithm for the rank 2 system and showed that type reconstruction for ranks 3 and higher of system F is undecidable.
So type inference for rank-2 polymorphism is known to be decidable and an algorithm has been known since 1999. Haskell supports with its RankNTypes
language extension, but it enables rank-n polymorphism.
Which languages, if any, implement rank-2 parametric polymorphism but not System F?
Since type inference is decidable and has not a worst complexity, why have neither SML nor OCaml extended polymorphism to rank-2?
Why do we not see and read more about rank-2 polymorphism in the wild?
RankNTypes
is a generalization of this but it's possible to only opt into n = 2. – Enclosure