Category theory

From HaskellWiki
Revision as of 20:06, 1 June 2007 by EndreyMark (talk | contribs) (โ†’โ€ŽHaskell libraries and tools: [http://www.eyrie.org/~zednenem/2004/hsce/ Category extras by David Menendez]: libraries for e.g. comonads, infinite data typ)
Haskell theoretical foundations

General:
Mathematics - Category theory
Research - Curry/Howard/Lambek

Lambda calculus:
Alpha conversion - Beta reduction
Eta conversion - Lambda abstraction

Other:
Recursion - Combinatory logic
Chaitin's construction - Turing machine
Relational algebra

Category theory can be helpful in understanding Haskell's type system. There exists a "Haskell category", of which the objects are Haskell types, and the morphisms from types a to b are Haskell functions of type a -> b. Various other Haskell structures can be used to make it a Cartesian closed category.


Defintion of a category

A category ๐’žconsists of two collections:

Ob(๐’ž), the objects of ๐’ž

Ar(๐’ž), the arrows of ๐’ž (which are not the same as Arrows defined in GHC)

Each arrow f in Ar(๐’ž) has a domain, dom f, and a codomain, cod f, each chosen from Ob(๐’ž). The notation f:Aโ†’B means f is an arrow with domain A and codomain B. Further, there is a function โˆ˜ called composition, such that gโˆ˜f is defined only when the codomain of f is the domain of g, and in this case, gโˆ˜f has the domain of f and the codomain of g.

In symbols, if f:Aโ†’B and g:Bโ†’C, then gโˆ˜f:Aโ†’C.

Also, for each object A, there is an arrow idA:Aโ†’A, (often simply denoted as 1 or id, when there is no chance of confusion).

Axioms

The following axioms must hold for ๐’ž to be a category:

  1. If f:Aโ†’B then fโˆ˜idA=idBโˆ˜f=f (left and right identity)
  2. If f:Aโ†’B and g:Bโ†’C and h:Cโ†’D, then hโˆ˜(gโˆ˜f)=(hโˆ˜g)โˆ˜f (associativity)

Examples of categories

  • Set, the category of sets and set functions.
  • Mon, the category of monoids and monoid morphisms.
  • Monoids are themselves one-object categories.
  • Grp, the category of groups and group morphisms.
  • Rng, the category of rings and ring morphisms.
  • Grph, the category of graphs and graph morphisms.
  • Top, the category of topological spaces and continuous maps.
  • Preord, the category of preorders and order preserving maps.
  • CPO, the category of complete partial orders and continuous functions.
  • Cat, the category of categories and functors.
  • the category of data types and functions on data structures
  • the category of functions and data flows (~ data flow diagram)
  • the category of stateful objects and dependencies (~ object diagram)
  • the category of values and value constructors
  • the category of states and messages (~ state diagram)

Further definitions

With examples in Haskell at:

Categorical programming

Catamorphisms and related concepts, categorical approach to functional programming, categorical programming. Many materials cited here refer to category theory, so as an introduction to this discipline see the #See also section.

Haskell libraries and tools=

See also