Re: [Haskell-cafe] Prime numbers

Henning Thielemann wrote:
factors :: Integer -> Integer -> Bool factors m n | m == n = False | m < n = divides m n || factors (m+1) n
Btw. I find the recursion harder to understand than the explicit definition:
factors n = any (divides n) [2..(n-1)]
For what it's worth, I also found this function un-intuitive. What I'd expect a function called "factors" to do is exactly what yours does, and not what the one in the example does. Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /

On Tue, 2005-12-20 at 16:53 +0000, Daniel Carrera wrote:
Henning Thielemann wrote:
factors :: Integer -> Integer -> Bool factors m n | m == n = False | m < n = divides m n || factors (m+1) n
Btw. I find the recursion harder to understand than the explicit definition:
factors n = any (divides n) [2..(n-1)]
For what it's worth, I also found this function un-intuitive. What I'd expect a function called "factors" to do is exactly what yours does, and not what the one in the example does.
It helped me to read "factors m n" as "there is an integer between m and n-1 inclusive that divides n". Then the recursion made sense. Thielemann's "factors n" would read "there is an integer between 2 and n-1 inclusive that divides n". -- Bill Wood
participants (2)
-
Bill Wood
-
Daniel Carrera