nLab Haskell

Contents

Context

Type theory

natural deduction metalanguage, practical foundations

  1. type formation rule
  2. term introduction rule
  3. term elimination rule
  4. computation rule

type theory (dependent, intensional, observational type theory, homotopy type theory)

syntax object language

computational trinitarianism =
propositions as types +programs as proofs +relation type theory/category theory

logicset theory (internal logic of)category theorytype theory
propositionsetobjecttype
predicatefamily of setsdisplay morphismdependent type
proofelementgeneralized elementterm/program
cut rulecomposition of classifying morphisms / pullback of display mapssubstitution
introduction rule for implicationcounit for hom-tensor adjunctionlambda
elimination rule for implicationunit for hom-tensor adjunctionapplication
cut elimination for implicationone of the zigzag identities for hom-tensor adjunctionbeta reduction
identity elimination for implicationthe other zigzag identity for hom-tensor adjunctioneta conversion
truesingletonterminal object/(-2)-truncated objecth-level 0-type/unit type
falseempty setinitial objectempty type
proposition, truth valuesubsingletonsubterminal object/(-1)-truncated objecth-proposition, mere proposition
logical conjunctioncartesian productproductproduct type
disjunctiondisjoint union (support of)coproduct ((-1)-truncation of)sum type (bracket type of)
implicationfunction set (into subsingleton)internal hom (into subterminal object)function type (into h-proposition)
negationfunction set into empty setinternal hom into initial objectfunction type into empty type
universal quantificationindexed cartesian product (of family of subsingletons)dependent product (of family of subterminal objects)dependent product type (of family of h-propositions)
existential quantificationindexed disjoint union (support of)dependent sum ((-1)-truncation of)dependent sum type (bracket type of)
logical equivalencebijection setobject of isomorphismsequivalence type
support setsupport object/(-1)-truncationpropositional truncation/bracket type
n-image of morphism into terminal object/n-truncationn-truncation modality
equalitydiagonal function/diagonal subset/diagonal relationpath space objectidentity type/path type
completely presented setsetdiscrete object/0-truncated objecth-level 2-type/set/h-set
setset with equivalence relationinternal 0-groupoidBishop set/setoid with its pseudo-equivalence relation an actual equivalence relation
equivalence class/quotient setquotientquotient type
inductioncolimitinductive type, W-type, M-type
higher inductionhigher colimithigher inductive type
-0-truncated higher colimitquotient inductive type
coinductionlimitcoinductive type
presettype without identity types
set of truth valuessubobject classifiertype of propositions
domain of discourseuniverseobject classifiertype universe
modalityclosure operator, (idempotent) monadmodal type theory, monad (in computer science)
linear logic(symmetric, closed) monoidal categorylinear type theory/quantum computation
proof netstring diagramquantum circuit
(absence of) contraction rule(absence of) diagonalno-cloning theorem
synthetic mathematicsdomain specific embedded programming language

homotopy levels

semantics

Contents

Idea

Haskell is a typed functional programming language. It is named after Haskell Brooks Curry.

Properties

Category-theoretic properties

Viewed as a syntactic framework, we can identify a subset of Haskell called Hask\mathbf{Hask} that is often used to identify concepts used in basic category theory. One considers Haskell types as objects of a category whose morphisms are extensionally identified Haskell functions.

With \to and ×\times etc., we can work Hask\mathbf{Hask} almost as if it were even a Cartesian closed category. A particular problem is the polymorphic term undefined\text{undefined}, which is defined to be term of every type. It prevents, for example, initial objects (i.e. there’s no analog of the empty set). Or, when it comes to setting up the categorical product, the projections π 1\pi_1 and π 2\pi_2 couldn’t distinguish between (undefined,undefined)(\text{undefined},\text{undefined}) and just undefined\text{undefined}, spoiling uniqueness. A related deficit is that when it comes to passing functions as arguments, Haskell sees more than just Hask morphisms.

The standard notion of functors in Haskell are not terms of a Hask type but operate on one level above those, the kind level. If ‘7’ is of type ‘Int’ and ‘Int’ is of kind ‘U’, then a functor corresponds to a map ‘U \to U’. Functors form a class, in the sense used in computer science, i.e. a standardly employed abstraction or interface.

The object mappings of functors in Haskell are type formers (e.g. mapping a type of integers to the type of lists of such integers) and these are often used without any reference to the arrow mappings in the code. For each declaration of a functor, the user must code its action on the arrows (a function called ‘fmap’), which here are Haskell function terms. It must be noted that all algebraic laws (e.g. compatibility of functors with function concatenation in the sense of the definition of functors) are not checked or enforced by the Haskell compiler. That is to say, in this language, its written code is only checked for the arrow mapping of a user defined functor is well-typed, while the user could, in principle, declare a “‘Functor’” that doesn’t actually fulfill all the defining properties of a functor. Today, there are also software modules that implement category theoretical notions more abstractly, i.e. one may set up categories in which the arrows are not necessarily Haskell functions.

Haskell is famous for its use of monads (in computer science), a subclass of functors. Here, the unit (called ‘return’) and co-unit must be implemented. However, stemming from the way that monads are actually used by programmers, it is standard to implement the function ‘return’ and another function called ‘bind’, with infix ‘»=’, which is a composite of the functor and the two natural transformations and which can be derived from the others.

Lifted products

Expanding on the caveat above about undefined, the built-in products in Haskell are “lifted”, they are not exactly categorical products. For example, if we define

loop = loop 

then the element loop :: ((),()) is observably different from (loop,loop) :: ((),()). To see this, note that

(\(_,_)->()) (loop,loop)

terminates but

(\(_,_)->()) loop

does not terminate.

As a result, the built-in currying is not strictly speaking a bijection in Haskell. For example,

(uncurry . curry) (\(_,_)->()) loop

terminates but

(\(_,_)->()) loop

does not terminate.

It is consistent to have a cartesian closed category with a recursion operator, and indeed most semantic models of recursion in a call-by-name setting do actually form cartesian closed categories. In fact Haskell does provide “unboxed tuple” types, which are more like categorical products, but these are not so widely used.

Languages similar to Haskell but refining it from plain type theory to dependent type theory include

Coq and Agda is consistent with Homotopy type theory, while Idris is not.

A wiki platform based on Haskell, running texmath

proof assistants:

based on plain type theory/set theory:

based on dependent type theory/homotopy type theory:

based on cubical type theory:

based on modal type theory:

based on simplicial type theory:

For monoidal category theory:

For higher category theory:

projects for formalization of mathematics with proof assistants:

Other proof assistants

Historical projects that died out:

References

General

Joint introduction to functional programming in general and Haskell in particular:

Discussion of the category of Haskell types (see at relation between category theory and type theory and at monad (in computer science)) is in

History of Haskell:

Mathematics in Haskell

The use of Haskell in mathematics is discussed in the following references.

The Kenzo-program for constructive algebraic topology (computational topology) re-written in Haskell:

Last revised on September 27, 2023 at 10:18:11. See the history of this page for a list of all contributions to it.