Hello all,

Maybe this is a wrong place to report, but I have repeatedly performed "funny" calculation in GHCi with strange time report. The version of GHCi is:

  ___         ___ _
 / _ \ /\  /\/ __(_)
/ /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Prelude>

My machine: OS WinXP Pro SP2, Intel Core 2, 2GB RAM.

How to reproduce error:

:set +s
:set -02
:cd <path to the file in the attachment>
:l Primes
take 10000 primes1
<provides correct result and shows correct timing, about 636 seconds>
take 10000 primes2
<provides correct result, BUT INCORRECT TIMING - about -326 seconds>

Yes, that is not a typo. The report of time elapsed is: minus three hundred and twenty six seconds.


I'll try the newest version of the GHCi, but it is strange anyway and maybe it should be investigated...

Thanks,
 Dusan

module Primes (
          primes1
         ,primes2
         ,primes3
         ,primes2'
         ,primes3'
       ) where


candidates = map (\x -> (True,x)) [2..]
candidates' =  [2..]

skipmap f toSkip list = domap toSkip list
  where
    domap n (x:xs)
      | n > 1  =  x : domap (n-1) xs
      | True   =  f x : domap toSkip xs
    domap _ [] = []

primes1 = sieve candidates
  where
    sieve (pp@(isp,p):xs) 
      | isp  =  p : (sieve $ skipmap (\(_,v) -> (False,v)) p xs)
      | True =  sieve xs

primes1' = sieve candidates'
  where
    sieve (p:xs) 
      | p > 0  =  p : (sieve $ skipmap (\n -> if n>0 then (-n) else n) p xs)
      | True   =  sieve xs



sieve (p:xs) = p : sieve [y | y <- xs, y `mod` p /= 0]
sieve' (p:xs) = p : sieve [y | y <- xs, y `mod` p > 0]

primes2  = sieve [2..]
primes3 = 2 : sieve [3,5..]

primes2'  = sieve' [2..]
primes3' = 2 : sieve' [3,5..]

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to