For a first sight, you cannot use x <- [0..]*[0..] to mean 'all possible pairs x = a*b'. You would need to do something like [ (a*b, y) | a <- [0..], b <- [0..], a*b > 5, a*b < 500, and the rest of things ]
2013/5/14 John <knowledge1...@gmail.com> > 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 >
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe