Previously, we got around the "
bind outputs the same box-like type it receives" restriction by using
MonadEffect. However, we also explained that
ST, the monad used to run a computation that uses local mutable state, did not have an instance for
MonadEffect. This decision is intentional.
When we run production code, we want to uphold this restriction. However, when we are debugging code, this restriction can be very annoying. Fortunately, the Debug package exists to help you use print debugging in any monadic context. You should use it when initially prototyping things. It should never appear in production code, nor as a solution for production-level logging. (We'll show how to do that in the
Application Structure folder).
Debug's functions are not always reliable when running concurrent code (i.e.
The warnings that will appear when compiling this code only appear once. Once you have built the code,
Use these commands
spago run -m Debugging.Debug spago run -m Debugging.LocalState