Last active
February 6, 2016 07:08
Revisions
-
kevin-lee revised this gist
Feb 6, 2016 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,5 +12,9 @@ let primes :: [Integer] -- where sieve (x : xs) = x : sieve [n | n <- xs, n `mod` x /= 0] take 10 primes -- result: -- [2,3,5,7,11,13,17,19,23,29] takeWhile (< 100) $ filter (> 10) primes -- result: -- [11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97] -
kevin-lee created this gist
Feb 6, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ let primes :: [Integer] primes = sieve [2..] where sieve :: [Integer] -> [Integer] sieve (x : xs) = x : sieve [n | n <- xs, n `mod` x /= 0] -- It works even without parameter types specified yet it is always good to have the type information -- as it tells the users of the function how to use it. -- It can also help you implement the function. -- primes without parameter types (Uncomment it if you want to try). -- let primes = sieve [2..] -- where sieve (x : xs) = x : sieve [n | n <- xs, n `mod` x /= 0] take 10 primes takeWhile (< 100) $ filter (> 10) primes