language-icon Old Web
English
Sign In

Dependent type

In computer science and logic, a dependent type is a type whose definition depends on a value. It is an overlapping feature of type theory and type systems. In intuitionistic type theory, dependent types are used to encode logic's quantifiers like 'for all' and 'there exists'. In functional programming languages like Agda, ATS, Coq, F*, Epigram, and Idris, dependent types may help reduce bugs by enabling the programmer to assign types that further restrain the set of possible implementations. In computer science and logic, a dependent type is a type whose definition depends on a value. It is an overlapping feature of type theory and type systems. In intuitionistic type theory, dependent types are used to encode logic's quantifiers like 'for all' and 'there exists'. In functional programming languages like Agda, ATS, Coq, F*, Epigram, and Idris, dependent types may help reduce bugs by enabling the programmer to assign types that further restrain the set of possible implementations. Two common examples of dependent types are dependent functions and dependent pairs. The return type of a dependent function may depend on the value (not just type) of one of its arguments. For instance, a function that takes a positive integer n {displaystyle n} may return an array of length n {displaystyle n} , where the array length is part of the type of the array. (Note that this is different from polymorphism and generic programming, both of which include the type as an argument.) A dependent pair may have a second value of which the type depends on the first value. Sticking with the array example, a dependent pair may be used to pair an array with its length in a type-safe way. Dependent types add complexity to a type system. Deciding the equality of dependent types in a program may require computations. If arbitrary values are allowed in dependent types, then deciding type equality may involve deciding whether two arbitrary programs produce the same result; hence type checking may become undecidable. Dependent types were created to deepen the connection between programming and logic. In 1934, Haskell Curry noticed that the types used in typed lambda calculus, and in its combinatory logic counterpart, followed the same pattern as axioms in propositional logic. Going further, for every proof in the logic, there was a matching function (term) in the programming language. One of Curry's examples was the correspondence between simply typed lambda calculus and intuitionistic logic. Predicate logic is an extension of propositional logic, adding quantifiers. Howard and de Bruijn extended lambda calculus to match this more powerful logic by creating types for dependent functions, which correspond to 'for all', and dependent pairs, which correspond to 'there exists'. (Because of this and other work by Howard, propositions-as-types is known as the Curry–Howard correspondence.) Loosely speaking, dependent types are similar to the type of an indexed family of sets. More formally, given a type A : U {displaystyle A:{mathcal {U}}} in a universe of types U {displaystyle {mathcal {U}}} , one may have a family of types B : A → U {displaystyle B:A o {mathcal {U}}} , which assigns to each term a : A {displaystyle a:A} a type B ( a ) : U {displaystyle B(a):{mathcal {U}}} . We say that the type B(a) varies with a. A function whose type of return value varies with its argument (i.e. there is no fixed codomain) is a dependent function and the type of this function is called dependent product type, pi-type or dependent function type. For this example, the dependent function type is typically written as

[ "Type theory", "Lambda calculus", "Diabetes mellitus", "Algorithm", "Discrete mathematics" ]
Parent Topic
Child Topic
    No Parent Topic