Re: [Haskell-cafe] (state) monad and CPS

2009-11-12 Thread jean-christophe mincke
Hello, Thank everybody for the answers. I must admit that I did not really emphasize the goal behind my initial question. Which is better expressed this way: 'walk' is written is CPS and is tail recursive. Unless I am wrong , if the continuation monad is used, the recursive calls to 'walk' are

Re: [Haskell-cafe] (state) monad and CPS

2009-11-12 Thread Nicolas Pouillard
Excerpts from wren ng thornton's message of Thu Nov 12 08:17:41 +0100 2009: Nicolas Pouillard wrote: Excerpts from jean-christophe mincke's message of Tue Nov 10 21:18:34 +0100 2009: do acc - get put (acc+1) ... Since this pattern occurs often 'modify' is a combination of

Re: [Haskell-cafe] (state) monad and CPS

2009-11-11 Thread Nicolas Pouillard
Excerpts from jean-christophe mincke's message of Tue Nov 10 21:18:34 +0100 2009: Hello, Hello, I would like to get some advice about state monad (or any other monad I guess) and CPS. Here is to remarks somewhat off topic: [...] walk Empty acc k = k acc walk (Leaf _) acc k = k (acc+1)

Re: [Haskell-cafe] (state) monad and CPS

2009-11-11 Thread wren ng thornton
Nicolas Pouillard wrote: Excerpts from jean-christophe mincke's message of Tue Nov 10 21:18:34 +0100 2009: do acc - get put (acc+1) ... Since this pattern occurs often 'modify' is a combination of get and put: do modify (+1) ... Though the caveat about laziness applies here as

[Haskell-cafe] (state) monad and CPS

2009-11-10 Thread jean-christophe mincke
Hello, I would like to get some advice about state monad (or any other monad I guess) and CPS. Let's take a simple exemple (see the code below) 'walk' is a function written in CPS that compute the number of nodes leaves in a tree. It use a counter which is explicitly passed through calls.

Re: [Haskell-cafe] (state) monad and CPS

2009-11-10 Thread Gregory Crosswhite
Yes; check out the module Control.Monad.Cont, which has a monad for continuation passing style. In particular, note that most of the monads in Control.Monad.* are stackable in that there is a version of the monad which you can stack on top of an existing monad. So for example, you could

Re: [Haskell-cafe] (state) monad and CPS

2009-11-10 Thread Ryan Ingram
Something like this should work: newtype ContState r s a = ContState { runCS :: s - (a - s - r) - r } instance Monad (ContState r s) where return a = ContState $ \s k - k a s m = f = ContState $ \s0 k - runCS m s $ \a s1 - runCS (f a) s1 k instance MonadState s (ContState r s) where