Skip to content

Instantly share code, notes, and snippets.

@axman6
Created November 1, 2021 23:34
Show Gist options
  • Save axman6/79be372a4b8507432bcabea42c488c62 to your computer and use it in GitHub Desktop.
Save axman6/79be372a4b8507432bcabea42c488c62 to your computer and use it in GitHub Desktop.
An infinite list of primes, using mutual recursion
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