[Haskell-cafe] Re: Query on list comprehension

Richard O'Keefe ok at cs.otago.ac.nz
Thu Mar 19 17:32:43 EDT 2009

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".

To produce the specified output using that pattern, you need
     (take 3 . tail . iterate ('a':)) "\n"
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.

More information about the Haskell-Cafe mailing list