
At 2010-10-05T09:21:51+13:00, Richard O'Keefe wrote:
answer s = concat $ zipWith replicate [1..] s
I looked at the examples and said, "hmm, elements are being repeated varying numbers of times". Looked up "repeat", found that that was the wrong function, and saw "replicate", which is the right one: replicate n x = [x ..... x] with n copies of x So zipWith [1..] "abcd" is ["a", "bb", "ccc", "dddd"] and pasting those together is just what concat does.
Had replicate, zipWith, concat not already been provided, I might have done one of two things.
Many thanks for the detailed explanation. It is instructive because I
thought of a solution in a different way. Another lesson is that I must
know the Prelude well. I've also installed `pointfree'. Together with
Hlint, it seems a useful tool for learning; for one thing, both of them
tell me about functions I didn't know earlier.
Regards,
Raghavendra.
--
N. Raghavendra