[Haskell-cafe] Noob question about list comprehensions

Tako Schotanus tako at codejive.org
Wed Feb 16 10:19:43 CET 2011


Hello,

I was going through some of the tuturials and trying out different
(syntactic) alternatives to the given solutions and I I got to this line:

    *length [chain x | x <- [1..100] , length (chain x) > 15]*

Now, there's nothing wrong with it, it works of course. But the application
of chain x is repeated twice and I wondered if there was a way for a guard
in a list comprehension to refer to the item being produced?

Like this for example (invented syntax):

    *length [@c(chain x) | x <- [1..100] , length c > 15]*

NB: Just to make clear, I'm not asking if there is an alternative way of
preventing the repetition, of course there is, I'm just wondering about this
very specific case within list comprehensions.

-Tako
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110216/9f4cc2ec/attachment.htm>


More information about the Haskell-Cafe mailing list