Arie Groeneveld wrote:

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

> Which one is the most elegant one generally speaking?

I like that tm only uses div.

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

You can make tm whereless by noticing that you use because
you use the function twice in  iterate f . f, which is because
you don't want the initial value that iterate gives.
You can instead use tail on iterate's result, and use a section
to avoid flip:

tm = sum . takeWhile (>0) . tail . iterate (`div` 5)

(Hope that works, can't test now...)


All the best
Christian Sievers
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to