<div dir="ltr">Hi, all.<div><br></div><div>While I know that foldr can be used on infinite list to generate infinite list,</div><div>I'm having difficulty in understaind following code:</div><div><div><font face="monospace, monospace" color="#000000"><br></font></div><div><font face="monospace, monospace" color="#000000" style="background-color:rgb(255,255,255)"><span style="font-size:13px;line-height:18px;white-space:pre">isPrime n = n > </span><span class="" style="font-size:13px;line-height:18px;white-space:pre">1</span><span style="font-size:13px;line-height:18px;white-space:pre"> &&  -- from haskell wiki</span><span style="font-size:13px;line-height:18px;white-space:pre">
        foldr (\p r -> p*p > n || ((n `rem` p) /= </span><span class="" style="font-size:13px;line-height:18px;white-space:pre">0</span><span style="font-size:13px;line-height:18px;white-space:pre"> && r)) </span><span class="" style="font-size:13px;line-height:18px;white-space:pre">True</span><span style="font-size:13px;line-height:18px;white-space:pre"> primes
primes = </span><span class="" style="font-size:13px;line-height:18px;white-space:pre">2</span><span style="font-size:13px;line-height:18px;white-space:pre"> : filter isPrime [</span><span class="" style="font-size:13px;line-height:18px;white-space:pre">3</span><span style="font-size:13px;line-height:18px;white-space:pre">,</span><span class="" style="font-size:13px;line-height:18px;white-space:pre">5.</span><span style="font-size:13px;line-height:18px;white-space:pre">.]</span><br></font><div><br></div></div></div><div>primes is a infinite list of prime numbers, and isPrime does foldr to get a boolean value.</div><div>What causes foldr to terminate folding? </div><div><br></div><div>Any helps will be deeply appreciated.</div><div><br></div><div>Thank you.</div><div><br></div><div>Chul-Woong</div></div>