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.fisc...@web.de> wrote: From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-cafe] trace To: haskell-cafe@haskell.org Cc: "michael rice" <nowg...@yahoo.com> Date: Thursday, December 24, 2009, 3:52 PM #yiv1755006913 p, #yiv1755006913 li {white-space:pre-wrap;} Am Donnerstag 24 Dezember 2009 21:31:34 schrieb michael rice: > Can someone provide a simple example of tracing a function. > > Michael Is import Debug.Trace infixl 0 `debug` debug = flip trace dfib :: Int -> Integer dfib = let fib 0 = 0 fib 1 = 1 fib n = dfib (n-2) + dfib (n-1) `debug` "eval fib " ++ show n in (map fib [0 .. ] !!) *MFib> dfib 12 eval fib 12 eval fib 10 eval fib 8 eval fib 6 eval fib 4 eval fib 2 eval fib 3 eval fib 5 eval fib 7 eval fib 9 eval fib 11 144 the kind of example you're looking for?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe