diff options
Diffstat (limited to 'sieve.icl')
-rw-r--r-- | sieve.icl | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -2,13 +2,40 @@ module sieve // The standard Sieve of Eratosthenes. -import StdEnv +//import StdEnv + +(+) infixl 6 :: !Int !Int -> Int +(+) a b = code inline { + addI +} + +(-) infixl 6 :: !Int !Int -> Int +(-) a b = code inline { + subI +} + +(==) infix 4 :: !Int !Int -> Bool +(==) a b = code inline { + eqI +} + +(rem) infix 7 :: !Int !Int -> Int +(rem) a b = code inline { + remI +} + +fro :: !Int -> [Int] +fro i = [i:fro (i+1)] + +take :: Int [a] -> [a] +take 0 _ = [] +take n [x:xs] = [x:take (n-1) xs] NrOfPrimes :== 1000 // The sieve algorithm: generate an infinite list of all primes. -Start = take NrOfPrimes (sieve [2..]) +Start = take NrOfPrimes (sieve (fro 2)) where sieve [prime:rest] = [prime : sieve (filter prime rest)] |