[Haskell-cafe] Re: Query on list comprehension
jon.fairbairn at cl.cam.ac.uk
Fri Mar 20 05:22:49 EDT 2009
"Richard O'Keefe" <ok at cs.otago.ac.nz> writes:
> The problem we were asked about was specifically
> The code (iterate ('a':) "\n") does not give the right answer.
> It's not just that it produces an infinite list instead of three
> strings, it doesn't even start with the right string. It starts
> with "\n" when we need "a\n".
It was impossible to determine that from the question.
> To produce the specified output using that pattern, you need
> (take 3 . tail . iterate ('a':)) "\n"
take 9, surely?
> or any of several other alternatives.
> The original poster also didn't ask "what is the best way to do
> this", but specifically asked about doing it with list
> comprehension. Presumably this was an attempt to understand list
> comprehension better.
Perhaps, but as the OP didn't follow up to the message where
I said that it wasn't clear what the question was, by the
time Henning posted, I think he was justified in
generalising the question and taking the answer further.
This café is for discussion; it's not a suitable place for
asking a question, copying out the answer and disappearing
without further comment.
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
More information about the Haskell-Cafe