4 ms·
The state monad, in spite of the scary name, is an incredibly simple idea, being about functions with this signature: S => (A, S) That’s it. Of course this do
by bad_user 8y ago
The state monad, in spite of the scary name, is an incredibly simple idea, being about functions with this signature:
S => (A, S)
That’s it. Of course this doesn’t include the definition of the monad instance, however those operations come very naturally from trying to work with, to manipulate these functions. In fact many people reinvent the state monad.
Furthermore this does a great job of simplifying impure functions that manipulate state, because for those functions the state evolution does not appear in the signature. Or in other words the state is still there, as an implicit input and output to your function, but the type system can no longer protect you and the function's output will be dependent on the history of all previous function calls. That's anything but simple.
And yes, I believe you can explain it to 10 year olds. If the 10 year old can understand functions, he can understand this as well. Your grandma might have a problem with it though.