[Haskell-cafe] Re: about Haskell code written to be "too smart"

Jonathan Cast jonathanccast at fastmail.fm
Wed Mar 25 11:25:40 EDT 2009

On Wed, 2009-03-25 at 15:09 +0000, Simon Marlow wrote:
> the ordering that the state monad expects 
> (and I can never remember which way around they are in Control.Monad.State).

Really?  I found it obvious once I figured out it how simple it made
(>>=).  With the order from Control.Monad.State (with constructors

    a >>= f = \ s -> case s a of
       (x, s') -> f x s'

Reversing the order of the components of the result gives you

    a >>= f = \ s -> case s a of
        (s', x) -> f x s'

which just looks weird.

> Try doing it with mapAccumL, which is arguably the right abstraction,
> but 
> has the components the other way around.


    swap (a, b) = (b, a)

You'll never worry about the order of components of a pair again.  This
function is as indispensable as flip.


More information about the Haskell-Cafe mailing list