Hello all,

the following program changes behavior if translated using different options for ghc compiler. Is this correct or not? I used The Glorious Glasgow Haskell Compilation System, version 6.6. And I would expect in both cases behavior 1.

 But I may be wrong...

 Thanks for any resolution.

 Dusan


*Program:*

$ cat Test.hs
import System.IO.Unsafe
import System.IO

main = do
 putStr "Start...\n"
 putStr $ show $ falling' falling10000
 putStr "\n"
 putStr $ show $ sorted' rising10000
 putStr "Stop...\n"

sorted' [] = True
sorted' [_] = True
sorted' l = sx l 1
 where
   sx []  _ = True
   sx [_] _ = True
   sx (x:l@(y:ys)) n =
if n==1000 then unsafePerformIO (putChar '.' >> hFlush stdout) `seq` x<=y && sx l 1
     else x<=y && (sx l $! n+1)

falling' [] = True
falling' [_] = True
falling' l = sx l 1
 where
   sx []  _ = True
   sx [_] _ = True
   sx (x:l@(y:ys)) n =
if n==1000 then unsafePerformIO (putChar '.' >> hFlush stdout) `seq` x>=y && sx l 1
     else x>=y && (sx l $! n+1)

rising10000 = [0..100000]

falling10000 = [100000,99999..0]

-- EOF



*Behavior 1:*

$ ghc Test.hs -o test
$ ./test
Start...
....................................................................................................True
....................................................................................................TrueStop...


*Behavior 2:*

$ rm test Test.o Test.hi
$ ghc -O2 Test.hs -o test
$ ./test
Start...
.True
.TrueStop...

--

Dusan Kolar            tel: +420 54 114 1238
UIFS FIT VUT Brno      fax: +420 54 114 1270
Bozetechova 2       e-mail: [EMAIL PROTECTED]
Brno 612 66
Czech Republic

--

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to