Here is a generic memoization module in Haskell. There are three
exports. Memoized a b is the type of a memoized function from as
to bs, recall makes a memoized function call, and forget makes a
memoized function call, forgets the memoization table, and gives you
the result.
And it’s use, for our old friend the Fibonacci sequence,
There are two things lacking with this approach. First, there is no
support for functions of more than one argument (without manually
packing and unpacking them). Second, it exposes the memoization
table. A user of the module could use the get and put functions.