Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-30 Thread Junior White
Thank you everyone! I like Haskell because the following two reasons: 1. It is beautifully 2. There are many great guys like you here. I will work harder on it, and forgive me for my broken English. On Thu, Jan 31, 2013 at 12:41 AM, Rustom Mody wrote: > > > On Wed, Jan 30, 2013 at 5:32 PM, Ju

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-30 Thread Rustom Mody
On Wed, Jan 30, 2013 at 5:32 PM, Junior White wrote: > > > Thanks for your reply! I must learn more to fully understand what's going > on inside the list comprehension. > But when I frist learn Haskell, it says sequence doesn't matter, but now > it is a big matter, can compiler do some thing for

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-30 Thread Brandon Allbery
On Wed, Jan 30, 2013 at 7:02 AM, Junior White wrote: > Thanks for your reply! I must learn more to fully understand what's going > on inside the list comprehension. > But when I frist learn Haskell, it says sequence doesn't matter, but now > it is a big matter, can compiler do some thing for us?

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-30 Thread Junior White
Thinks! I think compiler should do this for us, isn't it? On Wed, Jan 30, 2013 at 7:54 PM, Adrian Keet wrote: > The whole point here is to evaluate both lists inside the list > comprehension only once. There is a very simple way to accomplish this: > > [q:qs | let qss = queens' (k-1), q <- [1.

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-30 Thread Junior White
On Wed, Jan 30, 2013 at 5:51 PM, Doaitse Swierstra wrote: > From the conclusion that both programs compute the same result it can be > concluded that the fact that you have made use of a list comprehension has > forced you to make a choice which should not matter, i.e. the order in > which to pl

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-30 Thread Adrian Keet
The whole point here is to evaluate both lists inside the list comprehension only once. There is a very simple way to accomplish this: [q:qs | let qss = queens' (k-1), q <- [1..n], qs <- qss] Here, queens' (k-1) is only evaluated once, and is shared for all q. (Note: If queens' (k-1) is polymo

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-30 Thread Doaitse Swierstra
From the conclusion that both programs compute the same result it can be concluded that the fact that you have made use of a list comprehension has forced you to make a choice which should not matter, i.e. the order in which to place the generators. This should be apparent from your code. My

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-30 Thread ok
> The difference is what's called "dynamic programming" (an utterly > non-intuitive and un-insightful name). It was meant to be. The name was chosen to be truthful while not revealing too much to a US Secretary of Defense of whom Bellman wrote: "His face would suffuse, he would turn red, and he

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-29 Thread wren ng thornton
On 1/29/13 4:25 AM, Junior White wrote: Hi Cafe, I have two programs for the same problem "Eight queens problem", the link is http://www.haskell.org/haskellwiki/99_questions/90_to_94. My two grograms only has little difference, but the performance, this is my solution: The difference is

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-29 Thread Richard O'Keefe
On 29/01/2013, at 10:59 PM, Junior White wrote: > So this is a problem in lazy evaluation language, it will not appear in > python or erlang, am i right? Wrong. Let's take Erlang: [f(X, Y) || X <- g(), Y <- h()] Does the order of the generators matter here? You _bet_ it does. First o

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-29 Thread Artyom Kazak
Junior White писал(а) в своём письме Tue, 29 Jan 2013 12:59:31 +0300: So this is a problem in lazy evaluation language, it will not appear in python or erlang, am i right? Not quite. Compilers of imperative languages don’t perform CSE (common subexpression elimination) either; `queens' (k

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-29 Thread Junior White
So this is a problem in lazy evaluation language, it will not appear in python or erlang, am i right? On Tue, Jan 29, 2013 at 5:54 PM, Junior White wrote: > Thanks again! I understand now. I'll be careful when the next time I use > list comprehension. > > > On Tue, Jan 29, 2013 at 5:48 PM, Arty

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-29 Thread Junior White
Thanks again! I understand now. I'll be careful when the next time I use list comprehension. On Tue, Jan 29, 2013 at 5:48 PM, Artyom Kazak wrote: > Junior White писал(а) в своём письме Tue, 29 Jan 2013 > 12:40:08 +0300: > > Hi Artyom, >>Thanks! But I don't understand why in the first case

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-29 Thread Artyom Kazak
Junior White писал(а) в своём письме Tue, 29 Jan 2013 12:40:08 +0300: Hi Artyom, Thanks! But I don't understand why in the first case "queens' (k-1)" is being recomputed n times? Because your list comprehension is just a syntactic sugar for concatMap (\q -> concatMap (\qs -

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-29 Thread Junior White
Hi Artyom, Thanks! But I don't understand why in the first case "queens' (k-1)" is being recomputed n times? On Tue, Jan 29, 2013 at 5:31 PM, Artyom Kazak wrote: > Junior White писал(а) в своём письме Tue, 29 Jan 2013 > 12:25:49 +0300: > > > The only different in the two program is in the f

Re: [Haskell-cafe] list comprehansion performance has hug different

2013-01-29 Thread Artyom Kazak
Junior White писал(а) в своём письме Tue, 29 Jan 2013 12:25:49 +0300: The only different in the two program is in the first is "q <- [1..n], qs <- queens' (k-1)," and the second is "qs <- queens' (k-1), q <- [1..n]". In the first case `queens' (k-1)` is being recomputed for every q (that

[Haskell-cafe] list comprehansion performance has hug different

2013-01-29 Thread Junior White
Hi Cafe, I have two programs for the same problem "Eight queens problem", the link is http://www.haskell.org/haskellwiki/99_questions/90_to_94. My two grograms only has little difference, but the performance, this is my solution: -- solution 1-