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
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
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,
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
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
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
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:
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
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
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
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,
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
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
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?
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 -
-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:
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
-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
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.
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
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
-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
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
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.
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
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 `;',
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
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 -
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
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
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
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
.
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
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.
34 matches
Mail list logo