<div dir="ltr">You can't write <div><br></div><div> [1..] * [1..]</div><div><br></div><div style>Since Haskell's lists aren't Nums</div><div style><br></div><div style>Instead you'd want to write something like</div>
<div style><br></div><div style>a<-[1..], b<-[1..], and then multiply them together manually.</div><div style><br></div><div style>But this still doesn't really work since it'll loop forever without finding any solutions. Haskell's list comprehensions don'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"><<a href="mailto:knowledge1202@gmail.com" target="_blank">knowledge1202@gmail.com</a>></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<-[0..], y<-[0..], x<-[0..]*[0..], x > 5, x < 500,<br>
(y*y) < 1001, mod y x == 0]<br>
<br>
However it doesn'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>