John Mann wrote:

>    Hello, I am working my way through Simon Thompson's
> Haskell book, and one exercise has me baffled. That is
> "how would you define the "length" function using
> "map" and "sum" "? Any help on this would be
> appreciated. 

Create a list of 1's of the same length as the input list (with map),
then compute its sum (with sum).

i.e.:
        length = sum . map (const 1)
or:
        length l = sum (map (const 1) l)
or:
        length l = sum (map (\x -> 1) l)

-- 
Glynn Clements <[EMAIL PROTECTED]>
_______________________________________________
Hugs-Users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/hugs-users

Reply via email to