[Haskell-beginners] foldr on infinite list to decide prime number
Chul-Woong Yang
cwyang at aranetworks.com
Tue Feb 2 01:32:10 UTC 2016
Hi, all.
While I know that foldr can be used on infinite list to generate infinite
list,
I'm having difficulty in understaind following code:
isPrime n = n > 1 && -- from haskell wiki foldr (\p r -> p*p > n || ((n
`rem` p) /= 0 && r)) True primes primes = 2 : filter isPrime [3,5..]
primes is a infinite list of prime numbers, and isPrime does foldr to get a
boolean value.
What causes foldr to terminate folding?
Any helps will be deeply appreciated.
Thank you.
Chul-Woong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160202/7402c4e7/attachment.html>
More information about the Beginners
mailing list