Type inference, Type inference - Example, Type inference - External link, Type inference - Hindley-Milner type inference algorithm, Type inference - The Algorithm
ARTICLES RELATED TO Type inference - External link
The common algorithm used to perform the type inference is the one now commonly referred to as Hindley-Milner or Damas-Milner algorithm.
The origin of this algorithm is the type inference algorithm for the simply typed lambda calculus, which was devised by Haskell B. Curry and Robert Feys in 1958.
In 1969 Roger Hindley extended this work and proved that their algorithm always inferred the most general type.
In 1978 Robin Milner, independently of Hindley's work, provided an equivalent algorithm,
In 1985 Luis Damas finally proved that Milner's algorithm i ...
For example, let us consider the Haskell function length, which may be defined as:
length [] = 0
length (first:rest) = 1 + length rest
From this, it is evident that the function handles lists as inputs, and the base case of this recursive function returns an integer (Haskell "Int"). So we can reliably construct a type signature
length :: [a] -> Int
Since there are no ad-hoc polymorphic subfunctions in the function definition, we can declare ...