[Haskell-cafe] ST.Lazy vs ST.Strict

Luke Palmer lrpalmer at gmail.com
Tue May 5 17:35:45 EDT 2009


On Tue, May 5, 2009 at 3:27 PM, Luke Palmer <lrpalmer at gmail.com> wrote:

> On Sun, May 3, 2009 at 11:27 AM, Tobias Olausson <tobsan at gmail.com> wrote:
>
>> Hello!
>> I have a program that is using ST.Strict, which works fine.
>> However, the program needs to be extended, and to do that,
>> lazy evaluation is needed. As a result of that, I have switched
>> to ST.Lazy to be able to do stuff like
>
>
>>
>> foo y = do
>>    x <- something
>>    xs <- foo (y+1)
>>    return (x:xs)
>
>
> As Ryan points out, this will not do what you want.  But that is
> incidental, not essential:
>
> foo y = do
>      x <- something
>      fmap (x:) $ foo (y+1)
>

Questioning my own reasoning, I must apologize.   I was wrong, these two
programs are identical and both do what you want.

Any references to the state *after* the infinite chain of foos will result
in _|_, but as long as "something" is the only place that state calls occur,
you will be fine.

I also suspect that ST.Lazy should be no less defined than ST.Strict in all
cases, modulo unsafe operations of course (you aren't doing those, are
you?), so you have encountered a bug.  Minimize the test case and submit a
bug report :-)

Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090505/5658c2a7/attachment-0001.htm


More information about the Haskell-Cafe mailing list