Principal type
Encyclopedia
In type theory
, the principal type of an expression is the most general possible type given an expression. One way to compute the principal type of an expression is by deploying Robinson's unification algorithm, which is used by the Hindley–Milner type inference algorithm.
Expressions always having a principal type, such as in the ML programming language, is considered a desirable property, as it allows the compiler to infer the intended type of an expression desired by the programmer, without having to guess as there is only one possible correct type. Many extensions to the type system of ML, such as polymorphic recursion
, can make the inference of the principal type decidable. Other extensions, such as Haskell
's generalized algebraic data type
s, destroy the principal type property of the language, requiring the use of type annotations or the compiler to "guess" the intended type from among several options.
Type theory
In mathematics, logic and computer science, type theory is any of several formal systems that can serve as alternatives to naive set theory, or the study of such formalisms in general...
, the principal type of an expression is the most general possible type given an expression. One way to compute the principal type of an expression is by deploying Robinson's unification algorithm, which is used by the Hindley–Milner type inference algorithm.
Expressions always having a principal type, such as in the ML programming language, is considered a desirable property, as it allows the compiler to infer the intended type of an expression desired by the programmer, without having to guess as there is only one possible correct type. Many extensions to the type system of ML, such as polymorphic recursion
Polymorphic recursion
In computer science, polymorphism recursion refers to a recursive parametrically polymorph function where the type parameter changes with each recursive invocation made instead of staying constant...
, can make the inference of the principal type decidable. Other extensions, such as Haskell
Haskell (programming language)
Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing. It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language. As a functional programming language, the...
's generalized algebraic data type
Generalized Algebraic Data Type
In functional programming, a generalized algebraic data type is a generalization of the algebraic data types of Haskell and ML, applying to parametric types.With this extension, the parameters of the return type of a data constructor can be freely chosen when declaring...
s, destroy the principal type property of the language, requiring the use of type annotations or the compiler to "guess" the intended type from among several options.