juan_gandhi: (VP)
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)
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? :)

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

May 2025

S M T W T F S
    1 2 3
456 7 8 9 10
11 121314151617
18192021222324
25262728293031

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 13th, 2025 02:49 pm
Powered by Dreamwidth Studios