[Haskell-cafe] Working inside the fold

Christian Maeder maeder at tzi.de
Fri Oct 7 05:13:28 EDT 2005


Greg Buchholz wrote:
>> nats     f unit = foldr f unit [1..]
> 
> *Main> nats (takeWhile_ [] (<15) (:)) []
> [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
> 
> ...That's a little bit ugly because you have to supply the unit value

This could be solved by defining:

 > nats     f = foldr f undefined [1..]

Christian


More information about the Haskell-Cafe mailing list