[Haskell-cafe] Why my program runs out of memory?

2010-06-25 Thread Vladimir Ch.
I'm trying to solve this problem: http://projecteuler.net/index.php?section=problemsid=44, and my program runs out of memory. I was wondering where I have a space leak, I thought that this program doesn't accumulate any data structures (i.e. should use constant memory): CODE BEGINS -- returns

[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 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