mirror of
https://github.com/rjNemo/functional-programming-jargon
synced 2026-06-06 02:26:43 +00:00
Extend category definition
This commit is contained in:
parent
1105aae3e1
commit
38cd3bebb1
1 changed files with 21 additions and 3 deletions
24
readme.md
24
readme.md
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue