Lably
Skip to content

Function type

  • 2 min read
  • 2 chapters

Related on Lably

Through Computer science, Mathematical logic and Variable (high-level programming language)

A function type depends on the type of the parameters and the result type of the function (it, or more accurately the unapplied type constructor · → ·, is a higher-kinded type). In theoretical settings and programming languages where functions are defined in curried form, such as the simply typed lambda calculus, a function type depends on exactly two types, the domain A and the range B. Here a function type is often denoted A → B, following mathematical convention, or BA, based on there existing exactly BA (exponentially many) set-theoretic functions mappings A to B in the category of sets. The class of such maps or functions is called the exponential object. The act of currying makes the function type adjoint to the product type; this is explored in detail in the article on currying.

The function type can be considered to be a special case of the dependent product type, which among other properties, encompasses the idea of a polymorphic function.

Programming languages

The syntax used for function types in several programming languages can be summarized, including an example type signature for the higher-order function composition function:

When looking at the example type signature of, for example C#, the type of the function compose is actually Func<Func<A,B>,Func<B,C>,Func<A,C>>.

Due to type erasure in C++11's std::function, it is more common to use templates for higher order function parameters and type inference (auto) for closures.

Sign in to keep reading

One more chapter is free with a Lably account.

More in Computing and communication