main.hs 687 B

1234567891011121314151617181920
  1. primes = primesImpl 2 []
  2. where
  3. primesImpl :: Integer -> [Integer] -> [Integer]
  4. primesImpl i primeList =
  5. if isPrime then
  6. i:(primesImpl (i+1) (primeList ++ [i]))
  7. else
  8. primesImpl (i+1) primeList
  9. where
  10. isPrime = isPrimeImpl primeList
  11. where
  12. isPrimeImpl [] = True
  13. isPrimeImpl (x:xs) =
  14. if i `mod` x == 0 then
  15. False
  16. else
  17. isPrimeImpl xs
  18. main = do
  19. putStrLn $ show $ sum $ takeWhile (<2000000) primes