Over the last number of months I spent some free time here and there to read in Monads. Since my university days, I have not worked with a functional language. So I really don’t remember Haskell and, of course, I have no idea about Scalaz.
It was a tough time to learn about onions, burritos and sandwiches, trying to match these products with Haskell code codes. Fortunately, I came across two key entries that gave me a-ha moment: the monads in the photos and another guy from the imperative code who simply wrote the equivalent:
a -> b becomes m[a] -> m[b] (functor)
a -> m[b] becomes m[a] -> m[b] (monad)
and applicative is just a "function with context"
Together with the simplest sentence describing the purpose of the binding, many categories of endofuntors exploded and became entangled in simplicity.
Identity, list, maybe others unexpectedly made sense. Fueled by this knowledge, I started looking for an attempt at some TMP in C ++, using monadic types to see how this would evolve.
Very soon I wanted to propagate the state. I think that now I read more articles on state monads and monad transformers than for monads, but for life I can not understand them. Many keyboards are worn out, I’m sure that all the words entered in these topics correspond to people like me.
But I ask you to suffer more.
a -> s -> (b, s)
The function takes a value and some state, returns a new value and a (possibly) changed state. Obviously, Binding should propagate both the return value and the state to the next function.
: , . , . a → s → (b, s) a → m [b].
"a", s → (b, s). , (monadic?) STATE WITH . : VALUE WRAPPED.
(-), , , . , . .
, , : , m [a] a → m [b], , - ... , .
, : ", [s] " a " , a → State [s] → (State [s], b)". , .
- , , , a → m [b] - ( ?). , , , Monad Transformers (?), .
, , .
( - )