You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+21-3Lines changed: 21 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ __Table of Contents__
29
29
*[Predicate](#predicate)
30
30
*[Contracts](#contracts)
31
31
*[Guarded Functions](#guarded-functions)
32
-
*[Categories](#categories)
32
+
*[Category](#category)
33
33
*[Value](#value)
34
34
*[Constant](#constant)
35
35
*[Functor](#functor)
@@ -324,9 +324,27 @@ addOne('some string') // Contract violated: expected int -> int
324
324
325
325
TODO
326
326
327
-
## Categories
327
+
## Category
328
328
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/)
0 commit comments