[Haskell-cafe] length defined with foldr

Henning Thielemann lemming at henning-thielemann.de
Thu Sep 20 10:04:15 EDT 2007


On Wed, 19 Sep 2007, Stefan O'Rear wrote:

> On Thu, Sep 20, 2007 at 04:17:54AM +0100, PR Stanley wrote:
>> Hi
>> length = foldr (. n . 1 + n) 0
>> Any idea how to define length with foldr. The above definition doesn't make
>> much sense.
>> Many thanks, Paul
>
> or, in ASCII concrete syntax
>
> length = foldr (\_ n -> 1 + n) 0

or

length = foldr (const succ) 0

:-) (But why foldr and not foldl' ? Working with lazy Peano numbers?)


More information about the Haskell-Cafe mailing list