Skip to content

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

Clone this wiki locally