Created
November 1, 2021 23:34
-
-
Save axman6/79be372a4b8507432bcabea42c488c62 to your computer and use it in GitHub Desktop.
An infinite list of primes, using mutual recursion
This file contains 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 characters
module Primes where | |
primes :: [Integer] | |
primes = 2 : 3 : filter isPrime [5,7..] | |
isPrime :: Integer -> Bool | |
isPrime n = all (\x -> n `mod` x /= 0) $ takeWhile (\x -> x*x <= n) primes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment