Just as the lambda calculus has variables ranging over functions, and binders for them, the second-order lambda calculus has variables ranging over types, and binders for them.
As an example, the fact that the identity function can have any type of the form A→ A would be formalized in System F as the judgement
where α is a type variable.
System F, together with even more expressive lambda calculi, can be seen as part of the lambda cube.
Then, with these two λ-terms, we can define some logic operators:
There really is no need for a IFTHENELSE function as one can just use raw Boolean typed terms as decision functions. However, if one is requested:
System F allows recursive constructions to be embedded in a natural manner, related to that in Martin-Löf's type theory. Abstract structures (S) are created using constructors. These are functions typed as:
Recursivity is manifested when itself appears within one of the types . If you have of these constructors, you can define the type of as:
For instance, the natural numbers can be defined as an inductive datatype with constructors
If we reverse the order of the curried arguments (i.e., ), then the Church numeral for is a function that takes a function f as argument and returns the power of f. That is to say, a Church numeral is a higher-order function -- it takes a single-argument function f, and returns another single-argument function.
The version of System F used in this article is as an explicitly-typed, or Church-style, calculus. The typing information contained in λ-terms makes type-checking straightforward. Joe Wells (1994) settled an "embarrassing open problem" by proving that type checking is undecidable for a Curry-style variant of System F, that is, one that lacks explicit typing annotations.
Wells' result implies that type inference for System F is impossible. A restriction of System F known as "Hindley-Milner", or simply "HM", does have an easy type inference algorithm and is used for many strongly typed functional programming languages such as Haskell 98 and ML. Over time, as the restrictions of HM-style type systems have become apparent, languages have steadily moved to more expressive logics for their type systems. As of 2008, the Haskell compiler, GHC, goes beyond HM, and now uses System F extended with non-syntactic type equality, for example.
System is the simply-typed lambda calculus; it includes no mappings from types to types. The System F described in this article is technically System ; that is, the system wherein all mappings from types to types take arguments which are strictly first-order (not functions themselves).
In general, there is a family of systems defined inductively by the kinds permitted in each system:
In the limit, we can define system to be
That is, is the system which allows functions from types to types where the argument (and result) may be of any order.
Note that although places no restrictions on the order of the arguments in these mappings, it does restrict the universe of the arguments for these mappings -- they must be types rather than values. System does not permit mappings from values to types (Dependent types), though it does permit mappings from values to values ( abstraction), mappings from types to values ( abstraction, sometimes written ) and mappings from types to types ( abstraction at the level of types)