Jonathan Cast wrote:
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
ignored):

    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.

It might look weird to you, but that's the way that GHC's IO and ST monads do it. It looks perfectly natural to me! (and you have the a and s the wrong way around in 'case s a', BTW).

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

Define

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

ew, that's far too crude.  I think you mean

  swap = uncurry $ flip (,)

Cheers,
        Simon
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to