[Haskell-cafe] Prime numbers

Daniel Carrera daniel.carrera at zmsl.com
Tue Dec 20 11:53:31 EST 2005


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.
    /


More information about the Haskell-Cafe mailing list