Re: how to make the function "length" from "map" and "sum"
Glynn Clements <[email protected]>
| Newsgroups | gmane.comp.lang.haskell.hugs.user |
|---|---|
| Message-ID | <[email protected]> |
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]>