[Haskell-cafe] Style

Arie Groeneveld bradypus at xs4all.nl
Fri Aug 24 03:18:24 EDT 2007


Hi,

I defined several functions for calculating the number
of trailing zero's of n!


tm = sum . takeWhile(>0) . iterate f . f
   where f = flip div 5

tm1 n = sum . takeWhile(>0) . map (div n . (5^)) $ [1..]
tm2 n = sum . takeWhile(>0) . map (div n) $ iterate ((*)5) 5
tm3 = sum . takeWhile(>0) . flip map (iterate ((*)5) 5) . div



Questions:

Which one is the most elegant one generally speaking?
Which one is most natural in Haskell?
Is there more 'beauty' to possible?


My personal choice is 'tm'.
I like 'tm3' (a revised version of tm2) in terms of
pointlessness and not having a 'where', but I think
it's a bit contrived because of the 'flip'.

Comments?



Thanks

@@i


More information about the Haskell-Cafe mailing list