Re: [Haskell-cafe] list comprehension doesn't work

2013-05-15 Thread Daniel Trstenjak
Hi Mateusz, I don't think my post was out of order at all and I don't understand why it sparked such an... energetic response - that wasn't my intent at all. A friendly response might contain the things you told John, but it could also be a bit more empathic, otherwise its easy to perceive

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-15 Thread Keshav Kini
Danny Gratzer danny.grat...@gmail.com writes: 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

[Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread John
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,

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Alejandro Serrano Mena
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

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Danny Gratzer
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

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread John
thanks to both! listPairs = [(a*b, y) | a - [0..], b - [0..], (a*b) 5, (a*b) 500, (y*y) 1001, mod y x == 0] Now I have it as you said, however the compiler complains about all y and x and says they are NOT in scope. Why is it so? I can't see any problem with that... -- View this message

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Danny Gratzer
Well you've deleted the portion of the code referring to x and y. listPairs = [(a*b, y) | y - [0..], a - [0..], b - [0..], (a*b) 5, (a*b) 500, (y*y) 1001, mod y (a*b) == 0] This will still never terminate however. On Tue, May 14, 2013 at 10:17 AM, John knowledge1...@gmail.com wrote:

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Brandon Allbery
On Tue, May 14, 2013 at 11:17 AM, John knowledge1...@gmail.com wrote: listPairs = [(a*b, y) | a - [0..], b - [0..], (a*b) 5, (a*b) 500, (y*y) 1001, mod y x == 0] Now I have it as you said, however the compiler complains about all y and x and says they are NOT in scope. Why is it so? I

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Daniel Díaz Casanueva
You can always write it like this: listPairs = [ (x,y) | x - [6 .. 499] , y - [0 .. 1000] , isProduct x , isSqrt y , mod y x == 0 ] So you have the bounds for x and y, and then the conditions. You then need to define isProduct and isSqrt with types isProduct :: Int - Bool isSqrt :: Int - Bool

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Daniel Díaz Casanueva
Well, definitely, isSqrt should be called isSquare. On Tue, May 14, 2013 at 5:22 PM, Daniel Díaz Casanueva dhelta.d...@gmail.com wrote: You can always write it like this: listPairs = [ (x,y) | x - [6 .. 499] , y - [0 .. 1000] , isProduct x , isSqrt y , mod y x == 0 ] So you have the

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Danny Gratzer
Isn't the product check actually redundant? re-reading the requirements we could just define a = 1 and b = x. Maybe I'm misunderstanding though. On Tue, May 14, 2013 at 10:24 AM, Daniel Díaz Casanueva dhelta.d...@gmail.com wrote: Well, definitely, isSqrt should be called isSquare. On Tue,

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread John
Danny Gratzer wrote Well you've deleted the portion of the code referring to x and y. listPairs = [(a*b, y) | y - [0..], a - [0..], b - [0..], (a*b) 5, (a*b) 500, (y*y) 1001, mod y (a*b) == 0] This will still never terminate however. oh I see, but as you say it doesn't terminate and I

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread John
Danny Gratzer wrote Isn't the product check actually redundant? re-reading the requirements we could just define a = 1 and b = x. Maybe I'm misunderstanding though. I'm not sure. As I understand the requirement, the squer of y should not be greater than 1000. But anyway, without this condition

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Danny Gratzer
1. Does the order of conditions affect the result at all? Conditions, I don't believe so, the ordering/placement of bindings though can effect the results a great deal. When I say bindings, I mean something that involves a - 2. The , means AND or , right? So how do you write OR || instead?

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread John
is'nt it possible, to write it in one line without any nested functions in WHERE? If it's possible I'd prefer that... any idea? Thanks -- View this message in context: http://haskell.1045720.n5.nabble.com/list-comprehension-doesn-t-work-tp5730158p5730170.html Sent from the Haskell -

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Mateusz Kowalczyk
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 14/05/13 16:59, John wrote: is'nt it possible, to write it in one line without any nested functions in WHERE? If it's possible I'd prefer that... any idea? Thanks -- View this message in context:

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread John
thanks for your tips. As I said, I'm at the very beginning of Haskell. I try it to understand as much as I can, however the topic is very new to me. Sorry about my silly questions... You said, their is a mailing list for beginner? Could you please tell me I get to that? Thanks -- View this

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Mateusz Kowalczyk
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 14/05/13 17:53, John wrote: thanks for your tips. As I said, I'm at the very beginning of Haskell. I try it to understand as much as I can, however the topic is very new to me. Sorry about my silly questions... You said, their is a mailing

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Jerzy Karczmarczuk
MATEUSZ, There is nothing wrong with sending beginner questions to h-café! After all, a FRIENDLY community is for whom? For Simon PJ only? Notice that John got more than a dozen answers, people TRY to help him anyway. == On the other hand, the original requester *should* have thought on: 1.

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Daniel Díaz Casanueva
Hi John, On Tue, May 14, 2013 at 5:41 PM, John knowledge1...@gmail.com wrote: Danny Gratzer wrote Well you've deleted the portion of the code referring to x and y. listPairs = [(a*b, y) | y - [0..], a - [0..], b - [0..], (a*b) 5, (a*b) 500, (y*y) 1001, mod y (a*b) == 0] This

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Mark Lentczner
module Stuff where import Data.List -- Let's translate your specification directly into a list comprehension s1 :: [(Integer, Integer)] s1 = [(x,y) | x - [1..]-- for this problem, better to have 0 ∉ N , let a = 1 -- if 1 ∈ N, , let b = x -- then by

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Mateusz Kowalczyk
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 14/05/13 18:18, Jerzy Karczmarczuk wrote: MATEUSZ, There is nothing wrong with sending beginner questions to h-café! After all, a FRIENDLY community is for whom? For Simon PJ only? Notice that John got more than a dozen answers, people TRY

Re: [Haskell-cafe] list comprehension doesn't work

2013-05-14 Thread Richard A. O'Keefe
On 15/05/2013, at 2:57 AM, John 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