[Haskell-cafe] Style
Mirko Rahn
rahn at ira.uka.de
Fri Aug 24 05:04:09 EDT 2007
> tm = sum . takeWhile(>0) . iterate f . f
> where f = flip div 5
Quite nice. I like
tm5 0 = 0
tm5 n = let q = div n 5 in q + tm5 q
This version corresponds to what I'm think when parsing |tm|, so I wrote
it down directly.
Also possible
tm6 = sum . unfoldr ( \ n -> case div n 5 of
0 -> mzero
q -> return (q,q)
)
I tend to not use |iterate|, when it is known in advance, which prefix
of the so constructed infinite list is used.
/BR
--
-- Mirko Rahn -- Tel +49-721 608 7504 --
--- http://liinwww.ira.uka.de/~rahn/ ---
More information about the Haskell-Cafe
mailing list