[Haskell-beginners] Feedback on Maybe+State+IO code

shane pearman pearman.sm at gmail.com
Wed Apr 27 00:57:43 UTC 2016


I just read the M.P. Jones paper on the topic of monad transformers and
have been playing a bit with some simple examples combining `Maybe` and
`State` with `IO`: http://lpaste.net/6702944292505124864

I have the same "stuff" function defined 3 ways: two recursive methods, one
of which takes the "maybe" function as an argument which is used to break
the recursion, and a non-recursive method which is 'looped' using
`iterateM_`.

The functionality is that an integer is given as initial `State` and it is
decremented until 0 is reached, printing each iteration and breaking by the
result of the "maybe" function. I also wanted to ensure that no negative
integer could enter into the `State` so the same "maybe" function is used
in main to restrict entry into the "stuff" function, either using `for_`
over the result or injecting the `Maybe` before the "stuff" function.

The iterative calls are a little bit harder to read but the second (2)
recursive call is fairly concise and readable.

Basically I'm just looking for any suggestions if anything looks out of
place or can be refined before I go on to do more involved error handling
or logging.

* There are also a couple helper functions at the bottom below "main" that
I ended up not using but was wondering if they are defined somewhere.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160426/4d1da797/attachment.html>


More information about the Beginners mailing list