
On Tue, Apr 20, 2004 at 02:56:36PM +0200, Ketil Malde wrote:
Bernard James POPE
writes: Note each program was compiled with ghc 6.2 with -O2 on debian linux. : main = print $ loop 100000000 0
Isn't this going to be optimized away to a constant with -O2?
Here's the final stg code, obtained by: ghc -ddump-stg -O2 --make MainPure.hs -o pure ==================== STG syntax: ==================== Main.$wloop = \r [ww ww1] case ww of ds { __DEFAULT -> case +# [ww1 ds] of sat_s2pI { __DEFAULT -> case -# [ds 1] of sat_s2pE { __DEFAULT -> Main.$wloop sat_s2pE sat_s2pI; }; }; 0 -> ww1; }; SRT(Main.$wloop): [] Main.loop = \r [w w1] case w of w2 { GHC.Base.I# ww -> case w1 of w3 { GHC.Base.I# ww1 -> case Main.$wloop ww ww1 of ww2 { __DEFAULT -> GHC.Base.I# [ww2]; }; }; }; SRT(Main.loop): [] Main.eta = \u [] case Main.$wloop 100000000 0 of ww { __DEFAULT -> GHC.Base.I# [ww]; }; SRT(Main.eta): [] Main.lvl = \u srt:(0,*bitmap*) [] case Main.eta of w { GHC.Base.I# ww -> GHC.Show.$wshowSignedInt 0 ww GHC.Base.[]; }; SRT(Main.lvl): [Main.eta] Main.main = \r srt:(0,*bitmap*) [s] case GHC.IO.hGetLine GHC.Handle.stdin s of wild { GHC.Prim.(#,#) new_s a41 -> case GHC.IO.hPutStr GHC.Handle.stdout Main.lvl new_s of wild1 { GHC.Prim.(#,#) new_s1 a411 -> GHC.IO.$whPutChar GHC.Handle.stdout '\n' new_s1; }; }; SRT(Main.main): [GHC.Handle.stdout, GHC.IO.$whPutChar, GHC.IO.hPutStr, GHC.Handle.stdin, GHC.IO.hGetLine, Main.lvl] :Main.main = \r srt:(0,*bitmap*) [eta1] catch# [Main.main GHC.TopHandler.topHandler eta1]; SRT(:Main.main): [Main.main, GHC.TopHandler.topHandler]