[Haskell-cafe] [newbie question] Memoization automatic in Haskell?
David Benbennick
dbenbenn at gmail.com
Sat Jan 12 18:30:45 EST 2008
On 1/12/08, Henning Thielemann <lemming at henning-thielemann.de> wrote:
> Caching is not the default, but you can easily code this by yourself:
> Define an array and initialize it with all function values. Because of
> lazy evaluation the function values are computed only when they are
> requested and then they persist in the array.
But how can I implement memoization for a more complicated function?
For example, perhaps I want to memoize
f :: String -> Int -> Double -> String -> Bool
In Python, it's pretty easy to memoize this. How can I do it in
Haskell? I suspect the only way would involve changing the function
signature to use IO or ST.
It would be nice if I could just tell the compiler "I command you to
memoize this function", and have it produce the required code
automatically.
More information about the Haskell-Cafe
mailing list