
16 Sep
2010
16 Sep
'10
8:14 a.m.
Alex Rozenshteyn
I understand that
fib50 = slowFib 50
will take a while to run the first time but be instant each subsequent call; does this count as memoization?
I didn't see anybody else answering this in so many words, but I'd say no, since you only name one particular value. Memoization of slowFib would mean to provide a replacement for the *function* that remembers previous answers. Try e.g. these in GHCi (import (i.e. :m +) Data.Array for memoFib): slowFib 0 = 1; slowFib 1 = 1; slowFib x = slowFib (x-1) + slowFib (x-2) memoFib x = a!x where a = listArray (0,n) (1:1:[ a!(x-1)+a!(x-2) | x<-[2..99]]) -k -- If I haven't seen further, it is by standing in the footprints of giants