I have seen all the other memoization tricks and techniques in Haskell but what I am looking for is a straightforward implementation in the level of compiler/interpreter that takes care of memoization for me.
For example, consider the following code for the Fibonacci function:
fib 0 = 1
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
I want some kind of compiler option for ghc (or any other Haskell compiler) that executes the code above using memoization by default. For example, to compute "fib 10", one needs "fib 8" and "fib 9" to be computed first. Also, computing "fib 9" depends on first computing "fib 8". So, when computing "fib 10" I want the compiler/interpreter to understand that and compute "fib 8" only once.
Please note that I don't want to write a new Fibonacci function that takes care of memoization (as is the case with all other memoization questions in Haskell). What I want is to keep the function as above and still have memoization. I don't know if any Haskell compiler has that capability and that's part of my question. Do you know a Haskell compiler that can give me this?
Thanks
{-# MEMOISE #-}pragma, but for polymorphic functions, you'd probably need to give a list of types at which it should be memoised. However, I doubt that would be implemented, since hand-made memoisation is much more flexible and easy enough to do. - Daniel Fischer