Hmm... here are the functions I was looking to trace, the second one being an example from Scheme text "Concrete Abstractions" that I rewrote after seeing the first. Compared to the CL/Scheme memoization code, the Haskell seems like, how shall I put this, a sleight of hand, so much so that I'm driven to look behind the scenes to try to understand what is occurring. I remember that someone said, pattern matching is strict and LET is lazy, so I know the trick depends on laziness, but knowing that and understanding it are still a world apart. Does tracing a function *always* require memoizing it? Michael memo_fib :: Int -> Integer memo_fib = let fib 0 = 0 fib 1 = 1 fib n = memoized_fib (n-2) + memoized_fib (n-1) in (map fib [0..] !!) memo_walk_count :: Int -> Integer memo_walk_count = let walk_count 0 = 1 walk_count 1 = 1 walk_count n = memo_walk_count (n-2) + memo_walk_count (n-1) in (map walk_count [0..] !!) --- On Thu, 12/24/09, Daniel Fischer <daniel.is.fischer@web.de> wrote:
|