Memoization in Haskell
I can not understand memoization in Haskell. I can not find an example except the fib. For example, I want drop a list 4 times like,
drop 4 (drop 3 (drop 2 (drop 1 [1,2,3,4,5,6,7,8,9,10,11,12]))) [11,12]
can I implement a memoization funcation like
droploop [1,2,3,4] [1,2,3,4,5,6,7,8,9,10,11,12] to get same result [11,12]
so, if possible to do it? or any other example like it? Bright __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Bright Sun wrote:
I can not understand memoization in Haskell. I can not find an example except the fib.
For example, I want drop a list 4 times like,
drop 4 (drop 3 (drop 2 (drop 1 [1,2,3,4,5,6,7,8,9,10,11,12]))) [11,12]
can I implement a memoization funcation like
droploop [1,2,3,4] [1,2,3,4,5,6,7,8,9,10,11,12] to get same result [11,12]
That isn't memoization. Memoization is where you record a set of prior argument/result pairs (i.e. a lookup table) to avoid having to perform the exact same calculation repeatedly. You can implement droploop as a fold, e.g.: droploop ns xs = foldr drop xs ns -- Glynn Clements <glynn@gclements.plus.com>
participants (2)
-
Bright Sun -
Glynn Clements