News for hackers. Stuff that matters.
Re:State Monad for the Rest of Us by trealira on Friday August 09, 2024 @12:41PM (#41203413)
State can be modeled as a monad, but monads aren't a synonym for state. Just like squares are technically rectangles, but "rectangle" isn't a synonym for "square."

How do I think of the State monad?

- Like a Mealy machine: https://en.wikipedia.org/wiki/Mealy_machine

- Like a pure way to compose functions that use a nameless, global mutable variable.

- As a newtype wrapper over the type "s -> (a, s)" where s is the type of the state and a is the type of the computation.

There are no comments on this comment yet.