[Haskell-cafe] list comprehension doesn't work

Alejandro Serrano Mena trupill at gmail.com
Tue May 14 17:03:34 CEST 2013


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 <knowledge1202 at 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130514/0e2b013c/attachment.htm>


More information about the Haskell-Cafe mailing list