<div dir="ltr"><div>I feel sorry for posting mis-formatted code.</div><div>I re-post the question. </div><div>--</div><div><div><br></div><div>Hi, all.</div><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><br></div><div>isPrime n = n > 1 &&  -- from haskell wiki</div><div>        foldr (\p r -> p*p > n || ((n `rem` p) /= 0 && r)) True primes</div><div>primes = 2 : filter isPrime [3,5..]</div><div><br></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><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-02-02 10:32 GMT+09:00 Chul-Woong Yang <span dir="ltr"><<a href="mailto:cwyang@aranetworks.com" target="_blank">cwyang@aranetworks.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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-wrap">isPrime n = n > </span><span style="font-size:13px;line-height:18px;white-space:pre-wrap">1</span><span style="font-size:13px;line-height:18px;white-space:pre-wrap"> &&  -- from haskell wiki</span><span style="font-size:13px;line-height:18px;white-space:pre-wrap">
        foldr (\p r -> p*p > n || ((n `rem` p) /= </span><span style="font-size:13px;line-height:18px;white-space:pre-wrap">0</span><span style="font-size:13px;line-height:18px;white-space:pre-wrap"> && r)) </span><span style="font-size:13px;line-height:18px;white-space:pre-wrap">True</span><span style="font-size:13px;line-height:18px;white-space:pre-wrap"> primes
primes = </span><span style="font-size:13px;line-height:18px;white-space:pre-wrap">2</span><span style="font-size:13px;line-height:18px;white-space:pre-wrap"> : filter isPrime [</span><span style="font-size:13px;line-height:18px;white-space:pre-wrap">3</span><span style="font-size:13px;line-height:18px;white-space:pre-wrap">,</span><span style="font-size:13px;line-height:18px;white-space:pre-wrap">5.</span><span style="font-size:13px;line-height:18px;white-space:pre-wrap">.]</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><span class="HOEnZb"><font color="#888888"><div><br></div><div>Chul-Woong</div></font></span></div>
</blockquote></div><br></div>