Merge pull request #139 from hemanth/jethrolarson-patch-1-1

Extend category definition
This commit is contained in:
hemanth.hm 2017-01-27 16:55:25 +05:30 committed by GitHub
commit 4ff65ed282

View file

@ -29,7 +29,7 @@ __Table of Contents__
* [Predicate](#predicate)
* [Contracts](#contracts)
* [Guarded Functions](#guarded-functions)
* [Categories](#categories)
* [Category](#category)
* [Value](#value)
* [Constant](#constant)
* [Functor](#functor)
@ -324,9 +324,27 @@ addOne('some string') // Contract violated: expected int -> int
TODO
## Categories
## Category
A Category is a collection of objects (types) and functions (aka morphisms) between those types, typically sending values to values. Further, functions `a->b` and `b->c` can be composed into a new function `a->c`, the composition is associative, and there is identity function `a->a` for each object `a` that does not change functions by composing from right or from left.
A category in category theory is a collection of objects and morphisms between them. In programming, typically types
act as the objects and functions as morphisms.
To be a valid category 3 rules must be met:
1. There must be an identity morphism that maps an object to itself.
Where `a` is an object in some category,
there must be a function from `a -> a`.
2. Morphisms must compose.
Where `a`, `b`, and `c` are objects in some category,
and `f` is a morphism from `a -> b`, and `g` is a morphism from `b -> c`;
`g(f(x))` must be equivalent to `(g • f)(x)`.
3. Composition must be associative
`f • (g • h)` is the same as `(f • g) * h`
Since these rules govern composition at very abstract level, category theory is great at uncovering new ways of composing things.
### Further reading
* [Category Theory for Programmers](https://bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/)
## Value