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

David Menendez dave at zednenem.com
Mon May 4 00:52:04 EDT 2009


On Sun, May 3, 2009 at 7:54 PM, Tobias Olausson <tobsan at gmail.com> wrote:
> Would unsafeInterleaveST work just as unsafeInterleaveIO in the manner
> that it returns immediately, and then is computed lazily?
> The idea in the complete program is that one part representing
> the CPU will produce a list lazily, which will then be consumed
> lazily by another part of the program, which in turn will produce
> a lazy list fed to the CPU.

Like co-routines? It might be possible to do this with non-strict ST,
but it feels like it would be tricky to get right.

How are you feeding the lists from the two computations together? Are
they computed in the same ST thread?

> I might add that there was a base case for foo. It turns out i omitted
> that for "simplicity". Even stranger, if one adds the following
>
> foo y = do
>    if something then return y
>    else do
>       val <- foo (y+1)
>       fail "this is a fail"
>
> Will make the program fail with "this is a fail". Without the fail, that
> does not return the computed y. How come?

In the non-strict ST monad, the recursive call to foo does not get
evaluated until forced by an evaluation of val. That particular
version would work identically if you replaced the recursive call to
foo with "undefined".

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>


More information about the Haskell-Cafe mailing list