- There are
objects
andarrows
(morphisms) - Composition:
- If there's a morphism
f
fromA
toB
, and there's a morphismg
fromB
toC
, there must be a morphism fromA
toC
(g . f
). const compose = (f, g) => (x) => f(g(x))
- If there's a morphism
- Associativity of composition:
(h . g) . f == h . (g . f)
- Identity: For each
A
there must be a morphism fromA
toA
.const id = a => a
Types are sets of values>
In Set, objects are sets and morphisms are functions, and idenity maps each element to a set of itself.
Bottom (⊥
) is a value in every type, corresponding to a non-terminating
computation. Functions that can return bottom are partial functions.
Void
is a type with no values (empty set). There's only one function that can
return Void
, which is an idenity of Void
:
voidIdentity :: Void -> Void
voidIdentity a = a
()
is called 'unit,' which is similar to void
in imperative languages (think
C++). Usually used for functions with side effects or that discard arguments.
foo :: Char -> ()
foo _ = ()
There are two possible functions that just take a Bool
and return a Bool
:
const id = a => a
// id(true) -> true
const not = a => !a
// not(true) -> false
- Preorder is a category where morphisms are relations of being less than or equal.
- Partial order is preorder where for all
a <= b
andb <= a
,a == b
. - Linear order (aka total order) is partual order where any two objects are in a relation with each other, one way or another.
- Hom-set is a set of all morphisms from
a
tob
in categoryC
(C(a, b)
).
Monoid is a set with binary operation which is associative, and there must be a
unit
in the set.
-- the Monoid type class:
class Monoid m where
mempty :: m
mappend :: m -> m -> m
const left = a => ({ type: 'left', value: a })
const right = a => ({ type: 'right', value: a })
const m = e => {
if (e.type === 'left') return e.value
else return e.value ? 0 : 1
}