-
Notifications
You must be signed in to change notification settings - Fork 0
CTFP Ch04
WinChua edited this page May 3, 2020
·
4 revisions
在之前3章中,我们已经能够用type以及pure function作为category中的obj以及morphism, 但是没有涉及到side effect的model. 而kleisli category就是一种能够model side effect的category
- Writer Category
The starting point is our regular Category. Leave all the types as object, refine the morphism to the embelished function. To do this, there are two work to be finished:
1. redefined the morphism between object;
2. redefined the way of composition of the morphism;
1st point:
in the regular category, the morphism between int to bool is the function with func(int):bool signature,
but in kleisli category, the morphism between int to bool is func(int): (bool, type derived from some monoid).
2nd point:
in the regular category, the composition of morphism is : composition(f, g) = f . g, while in kleisli category, the composition between f and g maybe defined as:
c(f, g) = lambda i: x0, x1 = g(i); y0, y1 = f(x0); y0, mappend(x1, y1)
where x1, y1 belongs the set derived from the monoid
writer category重新定义了morphism以及morphism之间的组合方式, 让side effect在不同的函数之间进行传递
- Kleisli Category Kleisli Category is a category based on a monad. Kleisli Category has the types as objects. Morphism from Type A to Type B are functions that go from A to a type derived from B using the particular embellishment.
The embellishment is an endofunctor in a category.