Re:Do I really want to be using a language where memoize is ...
by johngunderman on Tuesday July 20, 2010 @04:53PM
(#1533405)
I had this discussion once, and was presented with the following options:
Ideally, lazy evaluation will automatically memoize all your computations. Haskell's 'thunk' system does this in part. However, doing full memoization on most functions will result in huge memory bloat. Which brings us to the essential trade off of memory vs. cpu time. By default, GHC will conserve memory and memoize only when it is obvious that you want values cached. If you want memoization, there are a few things you can do.
1) Add 'let' clauses to your function bodies. GHC will automatically memoize these.
2) Add certain compiler flags for automatic memoization (I don't know what these are, but I know they exist)
3) do it "semi-manually" by generating closures.
I'm sure there are other options, but these three are relatively simple to implement without even needing a memoize function (Though I'm sure one can be written).
Ideally, lazy evaluation will automatically memoize all your computations. Haskell's 'thunk' system does this in part. However, doing full memoization on most functions will result in huge memory bloat. Which brings us to the essential trade off of memory vs. cpu time. By default, GHC will conserve memory and memoize only when it is obvious that you want values cached. If you want memoization, there are a few things you can do.
1) Add 'let' clauses to your function bodies. GHC will automatically memoize these.
2) Add certain compiler flags for automatic memoization (I don't know what these are, but I know they exist)
3) do it "semi-manually" by generating closures.
I'm sure there are other options, but these three are relatively simple to implement without even needing a memoize function (Though I'm sure one can be written).