
On Jun 16, 2010, at 03:40 , Tom Hobbs wrote:
Why would I want to keep my functions monadic? It's not that I'm against the idea, rather it's that I don't understand the choice. I was under the (possibly wrong) impression that (IO) monadic functions were just to "get around" the issue of side-effects and that where possible functions should be coded outside of monads. Is that just plain wrong, or does it boil down to "It depends on what you're doing, and in this case..."?
Not all monads are IO. In this particular case, you'd be using the Get monad, which is essentially a custom State monad that carries deserialization state around for you. Avoiding IO is usually a good idea. But monads are your friends; state monads in particular get you out of a lot of boilerplate code, and Reader does the same with some useful localization capabilities. Writer is good for trace/log information; Maybe / Error / Cont are good for short-circuiting evaluation without building unwieldy case/if ladders, and Error is in particular good for pure "exceptions". Etc. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH