[Haskell-cafe] How to construct a lazy list of eagerly-evaluated items?

2010-05-22 Thread Vladimir Ch.
I'm using Project Euler to learn Haskell. In particular, I'm writing a program for Problem 18: http://projecteuler.net/index.php?section=problemsid=18. As a solution, I'm constructing a list, containing maximum sums of values on a path from top of the triangle to a given item. In this list, item

Re: [Haskell-cafe] How to construct a lazy list of eagerly-evaluated items?

2010-05-22 Thread Daniel Fischer
On Sunday 23 May 2010 01:10:54, Vladimir Ch. wrote: I'm using Project Euler to learn Haskell. In particular, I'm writing a program for Problem 18: snip The program works, but consumes obscene amount of memory. Not if it's compiled. Even interpreted I wouldn't call it obscene, though it is

Re: [Haskell-cafe] How to construct a lazy list of eagerly-evaluated items?

2010-05-22 Thread Vladimir Ch.
Not really. Your problem is that you calculate maxPaths vals over and over again in   where mpath i val = val + maximum [(maxPaths vals) !! pi| pi - prev i] ; the value isn't shared (it is, if compiled with optimisations). If you share the list by giving it a name, your programme becomes much