Joost Behrends wrote:
since about three weeks i am learning Haskell now. One of my first exercises is
to decompose an Integer into its primefactors.

How about separating the candidate prime numbers from the recursion

  factorize :: Integer -> [Integer]
  factorize = f primes'
     where
     primes' = 2:[3,5..]
     f (p:ps) n
        | r == 0    = p : f (p:ps) q
        | p*p > n   = [n]
        | otherwise = f ps n
        where
        (q,r) = n `divMod` p


For a faster factorization, just plug in a better  primes' .


Regards,
apfelmus

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to