You can't write 

    [1..] * [1..]

Since Haskell's lists aren't Nums

Instead you'd want to write something like

a<-[1..], b<-[1..], and then multiply them together manually.

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.


On Tue, May 14, 2013 at 9:57 AM, John <knowledge1202@gmail.com> wrote:
Hi,

I have to write a function which returns a list of all pairs (x,y) where x,
y ∈ N AND:
–  x is the product of two natural numbers (x = a · b, where a, b ∈ N) AND
–  x is really bigger than 5 but really smaller than 500, AND
–  y is a squer number (y = c² where c ∈ N) NOT greater than 1000, AND
–  x is a divisor of y.

My attempt is as follows:

listPairs :: [(Int, Int)]
listPairs = [(x,y) | x<-[0..], y<-[0..], x<-[0..]*[0..], x > 5, x < 500,
(y*y) < 1001, mod y x == 0]

However it doesn't work unfortunatly

Could anyone tell me where my mistake is?

Thanks.



--
View this message in context: http://haskell.1045720.n5.nabble.com/list-comprehension-doesn-t-work-tp5730158.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



--
Danny Gratzer