11 Jul
2003
11 Jul
'03
7:35 a.m.
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