-
To learn Monads I've followed these steps
- Implement an alias of a state transformer function - see
SimpleState
. - After that, replace the alias with a constructor and add the accessor function to apply the state transformer out of the monad - see
State
. OnlyrunState
needs to be exported now. - Finally, create the Monad instance for State, reusing the bind and the return functions. This State monad can be used in a do block - see
State
.StateMonad` - Implement a state monad with a transactional state inside that provides commit/rollback actions on the state -
see TransactionalStateMonad
.
- Implement an alias of a state transformer function - see
-
IMPORTANT: Monad formal definition available here
Run:
-
Compile and build executables:
stack build
-
Compile and run all tests:
stack test
-
List the tests you can run individually:
stack test --dry-run
-
Run an individual test:
stack test --test-arguments "--match=SimpleState"