Hello, <br><br>Thank everybody for the answers. <br><br>I must admit that I did not really emphasize the goal behind my initial question. Which is better expressed this way:<br><br>&#39;walk&#39; is written is CPS and is tail recursive. Unless I am wrong , if the continuation monad  is used, the recursive calls to &#39;walk&#39; are no longer in tail position.<br>
<br>So my initial question was rather: is it possible to use the state monad and keeping the code tail recursive?<br><br>I do not master all the subtilities of lazy evaluation yet and perhaps  tail recursivity does not have the same importance (or does not offer the same guarantees) in a lazy language as it does in a strict language.<br>
But I am facing a similar problem with workflows in F# (F#&#39;s monads).<br><br>Thank you<br><br>Regards<br><br>J-C<br><br><br><div class="gmail_quote">On Thu, Nov 12, 2009 at 8:17 AM, wren ng thornton <span dir="ltr">&lt;<a href="mailto:wren@freegeek.org">wren@freegeek.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Nicolas Pouillard wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">
Excerpts from jean-christophe mincke&#39;s message of Tue Nov 10 21:18:34 +0100 2009:<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
do acc &lt;- get<br>
   put (acc+1)<br>
   ...<br>
</blockquote><div class="im">
<br>
Since this pattern occurs often &#39;modify&#39; is a combination of get and put:<br>
<br>
do modify (+1)<br>
   ...<br>
</div></blockquote>
<br>
Though the caveat about laziness applies here as well. modify is famously lazy which can lead to space leaks and stack overflows. Better would be to define and use your own strict version:<br>
<br>
    modify&#39; f = get &gt;&gt;= \x -&gt; put $! f x<br>
<br>
-- <br>
Live well,<br><font color="#888888">
~wren</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>