<div dir="ltr">You can&#39;t write <div><br></div><div>    [1..] * [1..]</div><div><br></div><div style>Since Haskell&#39;s lists aren&#39;t Nums</div><div style><br></div><div style>Instead you&#39;d want to write something like</div>
<div style><br></div><div style>a&lt;-[1..], b&lt;-[1..], and then multiply them together manually.</div><div style><br></div><div style>But this still doesn&#39;t really work since it&#39;ll loop forever without finding any solutions. Haskell&#39;s list comprehensions don&#39;t play very nicely with multiple infinite lists. If you really want to use this style of programming for your problem, have a look at the logict package on Hackage, it has functions designed to solve the problem of multiple infinite choices.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 14, 2013 at 9:57 AM, John <span dir="ltr">&lt;<a href="mailto:knowledge1202@gmail.com" target="_blank">knowledge1202@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I have to write a function which returns a list of all pairs (x,y) where x,<br>
y ∈ N AND:<br>
–  x is the product of two natural numbers (x = a · b, where a, b ∈ N) AND<br>
–  x is really bigger than 5 but really smaller than 500, AND<br>
–  y is a squer number (y = c² where c ∈ N) NOT greater than 1000, AND<br>
–  x is a divisor of y.<br>
<br>
My attempt is as follows:<br>
<br>
listPairs :: [(Int, Int)]<br>
listPairs = [(x,y) | x&lt;-[0..], y&lt;-[0..], x&lt;-[0..]*[0..], x &gt; 5, x &lt; 500,<br>
(y*y) &lt; 1001, mod y x == 0]<br>
<br>
However it doesn&#39;t work unfortunatly<br>
<br>
Could anyone tell me where my mistake is?<br>
<br>
Thanks.<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://haskell.1045720.n5.nabble.com/list-comprehension-doesn-t-work-tp5730158.html" target="_blank">http://haskell.1045720.n5.nabble.com/list-comprehension-doesn-t-work-tp5730158.html</a><br>

Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.<br>
<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>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Danny Gratzer
</div>