John Goerzen wrote:
Which leaves me with an odd curiosity -- I still can't figure out how
state monads are anything but syntactic sugar (and lead more to
spaghetti code at that <g>)

Perhaps because state monads = syntactic sugar.

The state monad is just a nice(er) way of passing around some global state (Junk).

Without state monads
f :: Junk -> a -> (Junk, b)

With state monads,
f :: a -> State Junk b


....
Though if some function doesn't need to 'modify' your Junk, you find yourself having to re-factor things like,


decend :: Junk -> Exp -> Exp
decend state (Node a t1 t2)
 = Node a (decend state t1) (decend state t2)

into

decend :: Exp -> State Junk Exp
decend (Node a t1 t2)
 = do
        t1'     <- decend t1
        t2'     <- decend t2

        return   $ Node a t1' t2'


.. which IMHO is not as pretty.

Ben.


_______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to