I always thought that Haskell would do some sort of automatic intelligent memoizing. E.g., the naive Fibonacci implementation
fib 0 = 0
fib 1 = 1
fib n = fib
For example of implementing automatic memoization, you may look at the Factor programming language and its Memoization vocabulary. For example, simple Fibonacci number generator:
: fib ( n -- n )
dup 1 > [
[ 1 - fib ]
[ 2 - fib ]
bi +
] when ;
may be memoized by replacing ":" word with "MEMO:"
MEMO: fib ( n -- n )
dup 1 > [
[ 1 - fib ]
[ 2 - fib ]
bi +
] when ;
In that case, fib inputs and corresponding outputs will be transparently stored within in-memory dictionary.
Factor language syntax may be confusing :). I recommend you to watch video presentation from Google Tech Talks about Factor to understand, how is it possible to implement memoization in that way.