# Category theory

### From HaskellWiki

EndreyMark (Talk | contribs) m (Table of contents) |
(oops, already here...) |
||

(21 intermediate revisions by 13 users not shown) | |||

Line 1: | Line 1: | ||

+ | {{Foundations infobox}} | ||

+ | '''Category theory''' can be helpful in understanding Haskell's type system. There exists a [[Hask|"Haskell category"]], of which the objects are Haskell types, and the morphisms from types <hask>a</hask> to <hask>b</hask> are Haskell functions of type <hask>a -> b</hask>. | ||

+ | |||

__TOC__ | __TOC__ | ||

− | + | The Haskell wikibooks has [http://en.wikibooks.org/wiki/Haskell/Category_theory an introduction to Category theory], written specifically with Haskell programmers in mind. | |

− | + | ==Definition of a category== | |

+ | A category <math>\mathcal{C}</math>consists of two collections: | ||

+ | |||

+ | Ob<math>(\mathcal{C})</math>, the objects of <math>\mathcal{C}</math> | ||

+ | |||

+ | Ar<math>(\mathcal{C})</math>, the arrows of <math>\mathcal{C}</math> | ||

+ | (which are not the same as [[Arrow]]s defined in [[GHC]]) | ||

+ | |||

+ | Each arrow <math>f</math> in Ar<math>(\mathcal{C})</math> has a | ||

+ | domain, dom <math>f</math>, and a codomain, cod <math>f</math>, each | ||

+ | chosen from Ob<math>(\mathcal{C})</math>. The notation <math>f\colon | ||

+ | A \to B</math> means <math>f</math> is an arrow with domain | ||

+ | <math>A</math> and codomain <math>B</math>. Further, there is a | ||

+ | function <math>\circ</math> called composition, such that <math>g | ||

+ | \circ f</math> is defined only when the codomain of <math>f</math> is | ||

+ | the domain of <math>g</math>, and in this case, <math>g \circ f</math> | ||

+ | has the domain of <math>f</math> and the codomain of <math>g</math>. | ||

+ | |||

+ | In symbols, if <math>f\colon A \to B</math> and <math>g\colon B \to | ||

+ | C</math>, then <math>g \circ f \colon A \to C</math>. | ||

+ | |||

+ | Also, for each object <math>A</math>, there is an arrow | ||

+ | <math>\mathrm{id}_A\colon A \to A</math>, (often simply denoted as | ||

+ | <math>1</math> or <math>\mathrm{id}</math>, when there is no chance of | ||

+ | confusion). | ||

+ | |||

+ | ===Axioms=== | ||

+ | The following axioms must hold for <math>\mathcal{C}</math> to be a category: | ||

+ | |||

+ | #If <math>f\colon A \to B</math> then <math>f \circ \mathrm{id}_A = \mathrm{id}_B\circ f = f</math> (left and right identity) | ||

+ | #If <math>f\colon A \to B</math> and <math>g \colon B \to C</math> and <math>h \colon C \to D</math>, then <math>h \circ (g \circ f) = (h | ||

+ | \circ g) \circ f</math> (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. | ||

+ | |||

+ | * [[Hask]] | ||

+ | * 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: | ||

+ | * [[Category theory/Functor]] | ||

+ | * [[Category theory/Natural transformation]] | ||

+ | * [[Category theory/Monads]] | ||

== Categorical programming == | == 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 [[# | + | 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. |

− | * Erik Meijer, Maarten Fokkinga, Ross Paterson: [http:// | + | * Erik Meijer, Maarten Fokkinga, Ross Paterson: [http://research.microsoft.com/en-us/um/people/emeijer/Papers/fpca91.pdf Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire]. See also related documents (in the CiteSeer page). Understanding the article does not require knowledge of category theory—the paper is self-contained with regard to understanding catamorphisms, anamorphisms and other related concepts. |

+ | * Roland Backhouse, Patrik Jansson, Johan Jeuring and Lambert Mertens. [http://www.cse.chalmers.se/~patrikj/poly/afp98/ Generic Programming - an Introduction]: Detailed introduction to categorial sums, product, polynomial functors and folds for the purpose of generic programming. Supplements the bananas paper. | ||

* Varmo Vene and Tarmo Uustalu: [http://citeseer.ist.psu.edu/vene98functional.html Functional Programming with Apomorphisms / Corecursion] | * Varmo Vene and Tarmo Uustalu: [http://citeseer.ist.psu.edu/vene98functional.html Functional Programming with Apomorphisms / Corecursion] | ||

− | * Varmo Vene: [http://www.cs.ut.ee/~varmo/papers/thesis.pdf Categorical Programming with Inductive and Coinductive Types]. The book | + | * Varmo Vene: [http://www.cs.ut.ee/~varmo/papers/thesis.pdf Categorical Programming with Inductive and Coinductive Types]. The book gives Haskell examples to illustrate the deep categorical theory topic. |

* Tatsuya Hagino: [http://www.tom.sfc.keio.ac.jp/~hagino/thesis.pdf A Categorical Programming Language] | * Tatsuya Hagino: [http://www.tom.sfc.keio.ac.jp/~hagino/thesis.pdf A Categorical Programming Language] | ||

* [http://pll.cpsc.ucalgary.ca/charity1/www/home.html Charity], a categorical programming language implementation. | * [http://pll.cpsc.ucalgary.ca/charity1/www/home.html Charity], a categorical programming language implementation. | ||

* [http://okmij.org/ftp/Haskell/categorical-maxn.lhs Deeply uncurried products, as categorists might like them] article mentions a conjecture: relatedness to [[Combinatory logic]] | * [http://okmij.org/ftp/Haskell/categorical-maxn.lhs Deeply uncurried products, as categorists might like them] article mentions a conjecture: relatedness to [[Combinatory logic]] | ||

+ | |||

+ | ==Haskell libraries and tools== | ||

+ | |||

+ | * [http://www.eyrie.org/~zednenem/2004/hsce/ Category extras] by [http://www.eyrie.org/~zednenem/about/dave.html David Menendez]: libraries for e.g. comonads, infinite data types. | ||

+ | |||

+ | ==Books== | ||

+ | |||

+ | *Michael Barr and Charles Wells: [http://www.cwru.edu/artsci/math/wells/pub/ttt.html Toposes, Triples and Theories]. The online, freely available book is both an introductory and a detailed description of category theory. It also contains a category-theoretical description of the concept of ''monad'' (but calling it a ''triple'' instead of ''monad''). | ||

+ | |||

+ | *R. F. C. Walters: [http://www.cambridge.org/us/catalogue/catalogue.asp?isbn=0521419972 Categories and Computer Science]. Category Theory has, in recent years, become increasingly important and popular in computer science, and many universities now introduce Category Theory as part of the curriculum for undergraduate computer science students. Here, the theory is developed in a straightforward way, and is enriched with many examples from computer science. | ||

+ | |||

+ | * Arbib&Manes: Arrow, Structures and Functors - The Categorical Imperative. (c)1975 Academic Press, ISBN 0-12-059060-3. Sadly now out of print but very little prerequisite knowledge is needed. It covers monads and the Yoneda lemma. | ||

+ | |||

+ | ==See also== | ||

+ | |||

+ | * Michael Barr and Charles Wells have a [http://www.math.upatras.gr/~cdrossos/Docs/B-W-LectureNotes.pdf paper] that presents category theory from a computer-science perspective, assuming no prior knowledge of categories. | ||

+ | *[http://wwwhome.cs.utwente.nl/~fokkinga/mmf92b.html A Gentle Introduction to Category Theory - the calculational approach] written by [http://wwwhome.cs.utwente.nl/~fokkinga/index.html Maarten M Fokkinga]. | ||

+ | * Wikipedia has a good [http://en.wikipedia.org/wiki/List_of_category_theory_topics collection of category-theory articles], although, as is typical of Wikipedia articles, they are rather dense. | ||

[[Category:Theoretical foundations]] | [[Category:Theoretical foundations]] | ||

+ | [[Category:Mathematics]] |

## Revision as of 11:26, 16 September 2012

**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

## Contents |

The Haskell wikibooks has an introduction to Category theory, written specifically with Haskell programmers in mind.

## 1 Definition 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 means *f* is an arrow with domain
*A* and codomain *B*. Further, there is a
function called composition, such that is defined only when the codomain of *f* is
the domain of *g*, and in this case,
has the domain of *f* and the codomain of *g*.

In symbols, if and , then .

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

### 1.1 Axioms

The following axioms must hold for to be a category:

- If then (left and right identity)
- If and and , then (associativity)

### 1.2 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.

- Hask
- 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)

### 1.3 Further definitions

With examples in Haskell at:

## 2 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.

- Erik Meijer, Maarten Fokkinga, Ross Paterson: Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire. See also related documents (in the CiteSeer page). Understanding the article does not require knowledge of category theory—the paper is self-contained with regard to understanding catamorphisms, anamorphisms and other related concepts.
- Roland Backhouse, Patrik Jansson, Johan Jeuring and Lambert Mertens. Generic Programming - an Introduction: Detailed introduction to categorial sums, product, polynomial functors and folds for the purpose of generic programming. Supplements the bananas paper.
- Varmo Vene and Tarmo Uustalu: Functional Programming with Apomorphisms / Corecursion
- Varmo Vene: Categorical Programming with Inductive and Coinductive Types. The book gives Haskell examples to illustrate the deep categorical theory topic.
- Tatsuya Hagino: A Categorical Programming Language
- Charity, a categorical programming language implementation.
- Deeply uncurried products, as categorists might like them article mentions a conjecture: relatedness to Combinatory logic

## 3 Haskell libraries and tools

- Category extras by David Menendez: libraries for e.g. comonads, infinite data types.

## 4 Books

- Michael Barr and Charles Wells: Toposes, Triples and Theories. The online, freely available book is both an introductory and a detailed description of category theory. It also contains a category-theoretical description of the concept of
*monad*(but calling it a*triple*instead of*monad*).

- R. F. C. Walters: Categories and Computer Science. Category Theory has, in recent years, become increasingly important and popular in computer science, and many universities now introduce Category Theory as part of the curriculum for undergraduate computer science students. Here, the theory is developed in a straightforward way, and is enriched with many examples from computer science.

- Arbib&Manes: Arrow, Structures and Functors - The Categorical Imperative. (c)1975 Academic Press, ISBN 0-12-059060-3. Sadly now out of print but very little prerequisite knowledge is needed. It covers monads and the Yoneda lemma.

## 5 See also

- Michael Barr and Charles Wells have a paper that presents category theory from a computer-science perspective, assuming no prior knowledge of categories.
- A Gentle Introduction to Category Theory - the calculational approach written by Maarten M Fokkinga.
- Wikipedia has a good collection of category-theory articles, although, as is typical of Wikipedia articles, they are rather dense.