Skip to content

Commit 4ff65ed

Browse files
authored
Merge pull request #139 from hemanth/jethrolarson-patch-1-1
Extend category definition
2 parents 1105aae + 38cd3be commit 4ff65ed

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

readme.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ __Table of Contents__
2929
* [Predicate](#predicate)
3030
* [Contracts](#contracts)
3131
* [Guarded Functions](#guarded-functions)
32-
* [Categories](#categories)
32+
* [Category](#category)
3333
* [Value](#value)
3434
* [Constant](#constant)
3535
* [Functor](#functor)
@@ -324,9 +324,27 @@ addOne('some string') // Contract violated: expected int -> int
324324

325325
TODO
326326

327-
## Categories
327+
## Category
328328

329-
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.
329+
A category in category theory is a collection of objects and morphisms between them. In programming, typically types
330+
act as the objects and functions as morphisms.
331+
332+
To be a valid category 3 rules must be met:
333+
334+
1. There must be an identity morphism that maps an object to itself.
335+
Where `a` is an object in some category,
336+
there must be a function from `a -> a`.
337+
2. Morphisms must compose.
338+
Where `a`, `b`, and `c` are objects in some category,
339+
and `f` is a morphism from `a -> b`, and `g` is a morphism from `b -> c`;
340+
`g(f(x))` must be equivalent to `(g • f)(x)`.
341+
3. Composition must be associative
342+
`f • (g • h)` is the same as `(f • g) * h`
343+
344+
Since these rules govern composition at very abstract level, category theory is great at uncovering new ways of composing things.
345+
346+
### Further reading
347+
* [Category Theory for Programmers](https://bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/)
330348

331349
## Value
332350

0 commit comments

Comments
 (0)