<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
<font style="" face="Courier New">I can calculate non-nested list comprehensions without a problem, but am unable to calculate nested comprehensions involving, for example, the generation of a list of pairs where the first and separate elements are drawn from two separate lists, as in:<br><br></font><font style="" face="Courier New">&nbsp;&nbsp; [(a, b) | a &lt;- [1..3], b &lt;- [1..2]]</font><font style="" face="Courier New"><br>
</font><font style="" face="Courier New"><br>How does one calculate the expansion of this list?&nbsp; The two rules for expanding list comprehensions are:</font><br><font style="" face="Courier New"><br>1.&nbsp; Generator rule:&nbsp; [e | x &lt;- xs, Q]&nbsp; =&nbsp; concat (map f xs)</font><font style="" face="Courier New"><br></font><font style="" face="Courier New">&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where</font><font style="" face="Courier New"><br></font><font style="" face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f x = [e | Q]</font><font style="" face="Courier New"><br></font><font style="" face="Courier New"><br></font><font style="" face="Courier New">2.&nbsp; Guard rule: &nbsp; &nbsp;&nbsp; [e | p, Q]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; if p then [e | Q] else []</font><font style="" face="Courier New"><br></font><font style="" face="Courier New"><br></font><font style="" face="Courier New"><br></font><font style="" face="Courier New">There is a third rule that I've seen on the Internet, not in an authoritative text:<br>
</font><font style="" face="Courier New"><br>
&nbsp;&nbsp; [e | Q1 , Q2]&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; concat [ [e | Q 2] | Q1 ]<br>
<br>
I don't understand what this third rule means, or whether it's relevant.<br>
<br></font><font style="" face="Courier New">Concat and map are defined as:<br><br>concat&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :: [[a]] -&gt; [a]<br>concat []&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; []<br>concat (xs:xss)&nbsp; =&nbsp; xs ++ concat xss<br><br>map&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :: (a -&gt; b) -&gt; [a] -&gt; [b]<br>map f []&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; []<br>map f (x:xs)&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp; f x : (map f xs)<br></font><font style="" face="Courier New"><br>Any help is appreciated.<br></font><font style="" face="Courier New">
</font><font style="" face="Courier New"><br>
</font><br><br /><hr />Windows Live™: Keep your life in sync.  <a href='http://windowslive.com/explore?ocid=TXT_TAGLM_WL_allup_1b_explore_032009' target='_new'>Check it out.</a></body>
</html>