[Haskell-cafe] Help with identity functor print instance and monad transformers

Kim-Ee Yeoh ky3 at atamo.com
Tue Jan 20 05:26:05 UTC 2015

On Tue, Jan 20, 2015 at 12:09 PM, Cody Goodman <
codygman.consulting at gmail.com> wrote:

> type MyState = State Int
> modAndPrintState :: Int -> MyState ()
> modAndPrintState x = do
>   get >>= \i -> do
>     liftIO . print $ i
>     if even x then put (x + i) else put (i * (x + 1) - x)

This code works in the State monad and the only effect there is what it
says on the tin: state, not IO. So the code gets use of put and get, but
not print.

Others will soon chime in on StateT solutions, but from the looks of it,
you merely want to display the trace of the state. In which case look to

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150120/a12d8084/attachment.html>

More information about the Haskell-Cafe mailing list