[Hugs] #73: Sieve of Eratosthenes crashes if using "Integer" while not if using "Int"

Hugs trac at galois.com
Thu May 31 10:17:16 EDT 2007


#73: Sieve of Eratosthenes crashes if using "Integer" while not if using "Int"
--------------------+-------------------------------------------------------
 Reporter:  guest   |       Owner:  nobody
     Type:  defect  |      Status:  new   
 Priority:  minor   |   Milestone:        
Component:  hugs    |     Version:  200609
 Keywords:          |  
--------------------+-------------------------------------------------------
The following program crashes near the 5000th prime nr.

 sieveGH :: ([Integer], Integer) -> Integer
 sieveGH ([], y) = 0
 sieveGH ((p:xs), 0) = p
 sieveGH ((p:xs), y) = sieveGH ([x| x <- xs, x `mod` p /= 0], y-1)

 While the following does not crash, and i was taught that Integer was
 designed for near infinite/large calculations(?) :

 sieveGH :: ([Int], Int) -> Int
 sieveGH ([], y) = 0
 sieveGH ((p:xs), 0) = p
 sieveGH ((p:xs), y) = sieveGH ([x| x <- xs, x `mod` p /= 0], y-1)

 Main> sieveGH ([2..], 10000)
 104743
 (505275796 reductions, 696417680 cells, 787 garbage collections)

-- 
Ticket URL: <http://hackage.haskell.org/trac/hugs/ticket/73>
Hugs <http://www.haskell.org/hugs/>
Hugs 98, an interpreter for Haskell


More information about the Hugs-Bugs mailing list