Segmentation fault with primeList and primeSieve

Issue #16 new
Former user created an issue
primesSumWonk :: Int -> Int
primesSumWonk upto = sum . takeWhile (< upto) . map fromInteger . primeList $ primeSieve (toInteger upto)

primesSum :: Int -> Int
primesSum upto = sum . takeWhile (< upto) . map fromInteger $ primes

main = do
  hspec $
    describe "Primes.primesSumWonk" $
      it "works like primesSum" $
        property $ \n -> let upto = abs (n `rem` 45)

Try this a bunch of times with -a 100000, and soon enough, you'll get a segmentation fault.

Comments (2)

  1. David Feuer

    Sorry, I forgot to log in and lost the last line. main should've been

    main = do
      hspec $
        describe "Primes.primesSumWonk" $
          it "works like primesSum" $
            property $ \n -> let upto = abs (n `rem` 45)
                             in primesSum upto == primesSumWonk upto
    
  2. Log in to comment