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

Re: [Haskell-cafe] List comprehension

2009-05-06 Thread Martijn van Steenbergen
por...@porg.es wrote: -- or with Data.Function.Predicate (shameless plug) http://hackage.haskell.org/packages/archive/predicates/0.1/doc/html/Data-Function-Predicate.html: Whoa, a function called isn't, why is this the first time I see that? :-) Martijn.

[Haskell-cafe] List comprehension

2009-05-05 Thread applebiz89
Hi, I think I need to use a list comprehension for this function but Im not good with list comprehension. this is what I have so at the moment? filmsInGivenYear :: Int - [Film] - [String] filmsInGivenYear filmYear ?= [ title | year - (Film title director year fans) , year == filmYear] (this code

Re: [Haskell-cafe] List comprehension

2009-05-05 Thread Bulat Ziganshin
Hello applebiz89, Tuesday, May 5, 2009, 7:20:35 PM, you wrote: filmsInGivenYear :: Int - [Film] - [String] filmsInGivenYear filmYear ?= [ title | year - (Film title director year fans) , year == filmYear] (this code wont compile - error given '?Syntax error in expression (unexpected `;',

Re: [Haskell-cafe] List comprehension

2009-05-05 Thread minh thu
2009/5/5 applebiz89 applebi...@hotmail.com: Hi, I think I need to use a list comprehension for this function but Im not good with list comprehension. this is what I have so at the moment? filmsInGivenYear :: Int - [Film] - [String] filmsInGivenYear filmYear ?= [ title | year - (Film title

Re: [Haskell-cafe] List comprehension

2009-05-05 Thread Tillmann Rendel
Hi, applebiz89 wrote: Hi, I think I need to use a list comprehension There is no need to use list comprehensions, there is always a way to express the same thing without them. In fact, list comprehensions are defined as syntactic shorthands for this other way. filmsInGivenYear :: Int -

Re: [Haskell-cafe] List comprehension

2009-05-05 Thread Brent Yorgey
On Tue, May 05, 2009 at 05:36:12PM +0200, Tillmann Rendel wrote: PS. I'm not a native speaker, but shouldn't it be movies and not films? Both are correct. =) -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] List comprehension

2009-05-05 Thread porges
2009/5/6 Bulat Ziganshin bulat.zigans...@gmail.com: Hello applebiz89, Tuesday, May 5, 2009, 7:20:35 PM, you wrote: filmsInGivenYear :: Int - [Film] - [String] filmsInGivenYear filmYear ?= [ title | year - (Film title director year fans) , year == filmYear] (this code wont compile - error

[Haskell-cafe] List comprehension order of evaluation

2007-10-25 Thread Maurí­cio
Hi, Today, if I write: [a:[b] | a-ab , b-12] I get: [a1,a2,b1,b2] Are there any guarantees that I'll never get [a1,b1,a2,b2] instead, i.e., that the first list will always be the last one to be fully transversed? Even if I use a different compiler or a future version of Haskell? Reading how

Re: [Haskell-cafe] List comprehension order of evaluation

2007-10-25 Thread Jonathan Cast
On Thu, 2007-10-25 at 19:59 -0200, Maurí­cio wrote: Hi, Today, if I write: [a:[b] | a-ab , b-12] I get: [a1,a2,b1,b2] Are there any guarantees that I'll never get [a1,b1,a2,b2] instead, i.e., that the first list will always be the last one to be fully transversed? Even if I

Re: [Haskell-cafe] List comprehension order of evaluation

2007-10-25 Thread Thomas Hartman
. Maurí­cio [EMAIL PROTECTED] Sent by: [EMAIL PROTECTED] 10/25/2007 05:59 PM To haskell-cafe@haskell.org cc Subject [Haskell-cafe] List comprehension order of evaluation Hi, Today, if I write: [a:[b] | a-ab , b-12] I get: [a1,a2,b1,b2] Are there any guarantees that I'll never get [a1,b1,a2

[Haskell-cafe] List comprehension desugaring

2007-08-19 Thread Neil Mitchell
Hi, The Haskell desugaring for list comprehensions is given in: http://haskell.org/onlinereport/exps.html#list-comprehensions All the rules seem to be left to right rewrites, apart from the second one, which seems to be right to left. Is there some deep reason for this, or is this accidental.