Might better ways, but the following work:<br><br>length [c | x <- [1..100], let c = chain x , length c > 15]<br>length [c | x <- [1..100], c <- [chain x] , length c > 15]<br><br><br><div class="gmail_quote">
On Wed, Feb 16, 2011 at 9:19 AM, Tako Schotanus <span dir="ltr"><<a href="mailto:tako@codejive.org">tako@codejive.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello,<div><br></div><div>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:<br clear="all"><br></div><div> <b>length [chain x | x <- [1..100] , length (chain x) > 15]</b></div>
<div><br></div><div>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?</div>
<div><br></div><div>Like this for example (invented syntax):</div><div><br></div><div> <b>length [<font color="#ff0000">@c(</font>chain x<font color="#ff0000">)</font> | x <- [1..100] , length <font color="#ff0000">c</font> > 15]</b></div>
<div><br></div><div>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.</div>
<div><br>-Tako<br><br></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>