juan_gandhi: (VP)
2016-05-27 06:15 am
Entry tags:

State Monad, categorically

Take 1.
State[A,S] is just A×S, with a point s0:1→S.

- unit is provided by the point, A→A×S
- map is just a functoriality of cartesian product
- flatten is given by p1:S×S→S.

Take 2. OTOH, a pointed object S with a projection, p1:S×S→S, gives us a monoid.

What's the point then, why not take an arbitrary monoid M, and define State[A,M] using the monoidal properties of M?

Take 3.
It is (A×S)S, with the following operations:
- unit is given by currying id:A×S→A×S
- map is obvious
- flatten is given by some obvious and canonical (((A×S)S)×S)S → (A×S)S

So, the last one.
juan_gandhi: (VP)
2014-07-11 06:29 pm
Entry tags:

an exercise

so, can you write in Scala a web server using state monad, without any variable? :)
Kind of inverts your perception of what controls what, but who cares. It's just an FSM.

Is not it a nice exercise? :)