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

Tobias Olausson tobsan at gmail.com
Sun May 3 13:27:52 EDT 2009


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)

However, when running the program compiled with ST.Lazy, the
following is outputted:
   [tobsi at wobsi]$ ./runnerLazy looper.hex
   runnerLazy: <<loop>>

The very same program compiled with ST.Strict outputs:
   [tobsi at wobsi]$ ./runner looper.hex
   83298556

The code that is actually computing stuff is this:
loopSys :: Int -> CPU s Int
loopSys cc = do
    instr <- fetch
    if instr == 0xEA --NOP
       then return cc
       else do
         c <- execute instr
         loopSys $! (cc+c)

The CPU type looks as follows:
   type CPU s a = ReaderT (SysEnv s) (ST s) a

The program is run like
   runReaderT (loopSys 0)
which in turn is being runST'd and then printed

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


Tobias Olausson
tobsan at gmail.com


More information about the Haskell-Cafe mailing list