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

David Menendez dave at zednenem.com
Mon May 4 00:38:34 EDT 2009

On Sun, May 3, 2009 at 6:11 PM, Ryan Ingram <ryani.spam at gmail.com> wrote:
> So, I don't know what is causing your problem, but foo will not do
> what you want even with lazy ST.

That depends on what he wants to do. As long as nothing subsequent to
the call to foo tries to read a reference, then foo is fine.

For example, this works fine:

bar r = do
    x <- readSTRef r
    writeSTRef $! x + 1
    return x

> take 10 $ runST (newSTRef 0 >>= \r -> sequence (repeat (bar r)))

>> Does anyone know why the program just outputs <<loop>>
>> when compiled under ghc 6.10.2, and runs perfectly fine
>> under ghc 6.8.2? The program is compiled with --make and -O2

As I understand it, you get <<loop>> when the RTS detects a thunk
which depends on itself, which can happen if you're trying to do a
strict computation lazily.

I can't imagine why different versions of GHC would give different
results, though.

Dave Menendez <dave at zednenem.com>

More information about the Haskell-Cafe mailing list