[Haskell-cafe] (state) monad and CPS

jean-christophe mincke jeanchristophe.mincke at gmail.com
Thu Nov 12 03:07:46 EST 2009


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 no longer in
tail position.

So my initial question was rather: is it possible to use the state monad and
keeping the code tail recursive?

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.
But I am facing a similar problem with workflows in F# (F#'s monads).

Thank you

Regards

J-C


On Thu, Nov 12, 2009 at 8:17 AM, wren ng thornton <wren at freegeek.org> wrote:

> 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 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:
>
>    modify' f = get >>= \x -> put $! f x
>
> --
> Live well,
> ~wren
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091112/04a01617/attachment.html


More information about the Haskell-Cafe mailing list