[Haskell-cafe] Retaining functions in memory

Vo Minh Thu noteed at gmail.com
Tue Jul 26 12:06:40 CEST 2011


2011/7/26 Siddhartha Gadgil <siddhartha.gadgil at gmail.com>:
>       I have been making programs for mathematical applications
> (low-dimensional topology) in Haskell, which I find a delight to code
> in. However, the execution is slow, and this seems to be because
> recursively defined functions seem to be recomputed. For example
> f(100) needs f(15) which needs f(7) ... The dependencies are not
> obvious to the compiler.
>       I was looking for a way to retain the values of a specific
> function in memory. Is there some way to do this.

It seems you are looking for memoization. Have a look at the
comparison between slow/memoized_fib at this page
http://www.haskell.org/haskellwiki/Memoization#Memoization_with_recursion

Cheers,
Thu



More information about the Haskell-Cafe mailing list