[Haskell-cafe] Newbie: State monad example questions

Olivier Boudry olivier.boudry at gmail.com
Fri May 23 16:34:47 EDT 2008

On Fri, May 23, 2008 at 2:20 PM, Thomas Hartman <tphyahoo at gmail.com> wrote:

> > The big benefit I got from using the State Monad was that I was able to
> reorder the functions > by just copy/pasting the function name from one
> place to another.
> I don't understand... why do you need state to do this? Couldn't you
> have a function pipeline using dots for composition like
>  .... (
>    ...
>    parseAttn .
>    parsePoBox .
>    ...
>    ) address ...
> and have the functions be equally switchable? (well, the first and
> last can't quite be copy pasted, but close enough.)
> Introducing state seems like a lot of trouble to me if the only one is
> easier reorderability of lines.

Agreed, in fact I started with a function pipeline and then switched to
using the State Monad. As the program was written months ago I don't
remember exactly why. Maybe I don't like to read backwards. ;-)

Funtions running in the state monad can call other functions with the same
`State s a` signature (and so on as deep as you want). You never have to
care about passing parameters and restarting a new pipeline. But of course
you can easily do without the State Monad. I don't think the State Monad
allows to do thing that you can't do with basic Haskell. It just makes code
more readable (in my opinion at least).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080523/0c93fc09/attachment.htm

More information about the Haskell-Cafe mailing list