Re: [Haskell-cafe] How to incrementally update list

2012-12-02 Thread Albert Y. C. Lai

On 12-11-30 01:16 PM, Mark Thom wrote:

Is there a paper or other single resource that will help me thoroughly
understand non-strictness in Haskell?


See my http://www.vex.net/~trebla/haskell/lazy.xhtml

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to incrementally update list

2012-12-02 Thread Mark Thom
Thanks Albert, I believe that's the second time you've helped me this
weekend. I'm meiji11 in #haskell.

Cheers.

On Sun, Dec 2, 2012 at 1:34 PM, Albert Y. C. Lai tre...@vex.net wrote:

 On 12-11-30 01:16 PM, Mark Thom wrote:

 Is there a paper or other single resource that will help me thoroughly
 understand non-strictness in Haskell?


 See my 
 http://www.vex.net/~trebla/**haskell/lazy.xhtmlhttp://www.vex.net/~trebla/haskell/lazy.xhtml


 __**_
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to incrementally update list

2012-12-02 Thread Mark Thom
And thanks to everyone for the links and other suggestions, of course..

On Sun, Dec 2, 2012 at 5:09 PM, Mark Thom markjordant...@gmail.com wrote:

 Thanks Albert, I believe that's the second time you've helped me this
 weekend. I'm meiji11 in #haskell.

 Cheers.


 On Sun, Dec 2, 2012 at 1:34 PM, Albert Y. C. Lai tre...@vex.net wrote:

 On 12-11-30 01:16 PM, Mark Thom wrote:

 Is there a paper or other single resource that will help me thoroughly
 understand non-strictness in Haskell?


 See my 
 http://www.vex.net/~trebla/**haskell/lazy.xhtmlhttp://www.vex.net/~trebla/haskell/lazy.xhtml


 __**_
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to incrementally update list

2012-12-01 Thread Branimir Maksimovic

I want to simulate some calculation that does that.For example n-body 
simulation.Anyway this is solved ;)

 Date: Fri, 30 Nov 2012 13:25:57 -0800
 Subject: Re: [Haskell-cafe] How to incrementally update list
 From: kc1...@gmail.com
 To: bm...@hotmail.com
 CC: haskell-cafe@haskell.org
 
 Why do you want to incrementally update this list a lot of times?
 
 The question would affect the answer you get; i.e. some context
 (non-monadically speaking). :D
 
 
 On Wed, Nov 28, 2012 at 3:43 AM, Branimir Maksimovic bm...@hotmail.com 
 wrote:
  Problem is following short program:
  list = [1,2,3,4,5]
 
  advance l = map (\x - x+1) l
 
  run 0 s = s
  run n s = run (n-1) $ advance s
 
  main = do
  let s =  run 5000 list
  putStrLn $ show s
 
  I want to incrementally update list lot of times, but don't know
  how to do this.
  Since Haskell does not have loops I have to use recursion,
  but problem is that recursive calls keep previous/state parameter
  leading to excessive stack.and memory usage.
  I don't know how to tell Haskell not to keep previous
  state rather to release so memory consumption becomes
  managable.
 
  Is there some solution to this problem as I think it is rather
  common?
 
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 
 
 
 -- 
 --
 Regards,
 KC
  ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to incrementally update list

2012-11-30 Thread Mark Thom
 Haskell's laziness is tricky to understand coming from imperative
 languages, but once you figure out its evaluation rules, you'll begin to
 see the elegance.


Is there a paper or other single resource that will help me thoroughly
understand non-strictness in Haskell? Once my programs hit a certain level
of complexity, their behaviour becomes much harder for me to predict. I've
been using the wiki pages up to this point, but apparently they haven't
pushed my understanding of laziness nearly far enough.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to incrementally update list

2012-11-30 Thread Kim-Ee Yeoh
On Sat, Dec 1, 2012 at 1:16 AM, Mark Thom markjordant...@gmail.com wrote:

  Is there a paper or other single resource that will help me thoroughly
understand non-strictness in Haskell?

If performance is utterly vital the best resource is Core, as in, the
ability to read it. The order of evaluation is all laid out there. Don [1]
and Johan [2] have written variously about it.

[1] http://stackoverflow.com/questions/6121146/reading-ghc-core
[2]
http://blog.johantibell.com/2012/02/forcing-values-returned-from-monadic.html


-- Kim-Ee


On Sat, Dec 1, 2012 at 1:16 AM, Mark Thom markjordant...@gmail.com wrote:


 Haskell's laziness is tricky to understand coming from imperative
 languages, but once you figure out its evaluation rules, you'll begin to
 see the elegance.


 Is there a paper or other single resource that will help me thoroughly
 understand non-strictness in Haskell? Once my programs hit a certain level
 of complexity, their behaviour becomes much harder for me to predict. I've
 been using the wiki pages up to this point, but apparently they haven't
 pushed my understanding of laziness nearly far enough.

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to incrementally update list

2012-11-30 Thread KC
Why do you want to incrementally update this list a lot of times?

The question would affect the answer you get; i.e. some context
(non-monadically speaking). :D


On Wed, Nov 28, 2012 at 3:43 AM, Branimir Maksimovic bm...@hotmail.com wrote:
 Problem is following short program:
 list = [1,2,3,4,5]

 advance l = map (\x - x+1) l

 run 0 s = s
 run n s = run (n-1) $ advance s

 main = do
 let s =  run 5000 list
 putStrLn $ show s

 I want to incrementally update list lot of times, but don't know
 how to do this.
 Since Haskell does not have loops I have to use recursion,
 but problem is that recursive calls keep previous/state parameter
 leading to excessive stack.and memory usage.
 I don't know how to tell Haskell not to keep previous
 state rather to release so memory consumption becomes
 managable.

 Is there some solution to this problem as I think it is rather
 common?


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




-- 
--
Regards,
KC

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to incrementally update list

2012-11-28 Thread Benjamin Edwards
TCO + strictnesses annotations should take care of your problem.
On 28 Nov 2012 11:44, Branimir Maksimovic bm...@hotmail.com wrote:

  Problem is following short program:
 list = [1,2,3,4,5]

 advance l = map (\x - x+1) l

 run 0 s = s
 run n s = run (n-1) $ advance s

 main = do
 let s =  run 5000 list
 putStrLn $ show s

 I want to incrementally update list lot of times, but don't know
 how to do this.
 Since Haskell does not have loops I have to use recursion,
 but problem is that recursive calls keep previous/state parameter
 leading to excessive stack.and memory usage.
 I don't know how to tell Haskell not to keep previous
 state rather to release so memory consumption becomes
 managable.

 Is there some solution to this problem as I think it is rather
 common?


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to incrementally update list

2012-11-28 Thread Clark Gaebel
Here's a version that works:

*import Control.DeepSeq*

list = [1,2,3,4,5]

advance l = *force $* map (\x - x+1) l

run 0 s = s
run n s = run (n-1) $ advance s

main = do
let s =  run 5000 list
putStrLn $ show s

The problem is that you build of a huge chain of updates to the list. If we
just commit each update as it happens, we'll use a constant amount of
memory.

Haskell's laziness is tricky to understand coming from imperative
languages, but once you figure out its evaluation rules, you'll begin to
see the elegance.

Ηope this helps,
  - Clark


On Wed, Nov 28, 2012 at 7:07 AM, Benjamin Edwards edwards.b...@gmail.comwrote:

 TCO + strictnesses annotations should take care of your problem.
 On 28 Nov 2012 11:44, Branimir Maksimovic bm...@hotmail.com wrote:

  Problem is following short program:
 list = [1,2,3,4,5]

 advance l = map (\x - x+1) l

 run 0 s = s
 run n s = run (n-1) $ advance s

 main = do
 let s =  run 5000 list
 putStrLn $ show s

 I want to incrementally update list lot of times, but don't know
 how to do this.
 Since Haskell does not have loops I have to use recursion,
 but problem is that recursive calls keep previous/state parameter
 leading to excessive stack.and memory usage.
 I don't know how to tell Haskell not to keep previous
 state rather to release so memory consumption becomes
 managable.

 Is there some solution to this problem as I think it is rather
 common?


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to incrementally update list

2012-11-28 Thread Kim-Ee Yeoh
 I want to incrementally update list lot of times, but don't know how to
do this.

Are you using the right data structure for the job? Maybe you want an array
instead?

-- Kim-Ee


On Wed, Nov 28, 2012 at 6:43 PM, Branimir Maksimovic bm...@hotmail.comwrote:

  Problem is following short program:
 list = [1,2,3,4,5]

 advance l = map (\x - x+1) l

 run 0 s = s
 run n s = run (n-1) $ advance s

 main = do
 let s =  run 5000 list
 putStrLn $ show s

 I want to incrementally update list lot of times, but don't know
 how to do this.
 Since Haskell does not have loops I have to use recursion,
 but problem is that recursive calls keep previous/state parameter
 leading to excessive stack.and memory usage.
 I don't know how to tell Haskell not to keep previous
 state rather to release so memory consumption becomes
 managable.

 Is there some solution to this problem as I think it is rather
 common?


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to incrementally update list

2012-11-28 Thread Branimir Maksimovic

Thank you very much! That solved it ;)I had to put explicit type signature in 
front of advance in order to compile
From: cgae...@uwaterloo.ca
Date: Wed, 28 Nov 2012 08:01:38 -0500
Subject: Re: [Haskell-cafe] How to incrementally update list
To: edwards.b...@gmail.com
CC: bm...@hotmail.com; haskell-cafe@haskell.org

Here's a version that works:

import Control.DeepSeq

list = [1,2,3,4,5]
advance l = force $ map (\x - x+1) l


run 0 s = srun n s = run (n-1) $ advance s
main = dolet s =  run 5000 listputStrLn $ show s

The problem is that you build of a huge chain of updates to the list. If we 
just commit each update as it happens, we'll use a constant amount of memory.



Haskell's laziness is tricky to understand coming from imperative languages, 
but once you figure out its evaluation rules, you'll begin to see the elegance.

Ηope this helps,
  - Clark




On Wed, Nov 28, 2012 at 7:07 AM, Benjamin Edwards edwards.b...@gmail.com 
wrote:


TCO + strictnesses annotations should take care of your problem.
On 28 Nov 2012 11:44, Branimir Maksimovic bm...@hotmail.com wrote:







Problem is following short program:list = [1,2,3,4,5]
advance l = map (\x - x+1) l
run 0 s = srun n s = run (n-1) $ advance s



main = dolet s =  run 5000 listputStrLn $ show s
I want to incrementally update list lot of times, but don't knowhow to do this.


Since Haskell does not have loops I have to use recursion,but problem is that 
recursive calls keep previous/state parameterleading to excessive stack.and 
memory usage.I don't know how to tell Haskell not to keep previous


state rather to release so memory consumption becomesmanagable.
Is there some solution to this problem as I think it is rathercommon?
  




___

Haskell-Cafe mailing list

Haskell-Cafe@haskell.org

http://www.haskell.org/mailman/listinfo/haskell-cafe




___

Haskell-Cafe mailing list

Haskell-Cafe@haskell.org

http://www.haskell.org/mailman/listinfo/haskell-cafe



  ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe