I am interested in reasoning about a code,  say for example:

data DList a = DLNode (DList a) a (DList a)
 
mkDList :: [a] -> DList a
 
mkDList [] = error "must have at least one element"
mkDList xs = let (first,last) = go last xs first
in first
 
where go :: DList a -> [a] -> DList a -> (DList a, DList a)
go prev [] next = (next,prev)
go prev (x:xs) next = let this = DLNode prev x rest
(rest,last) = go this xs next


in (this,last)

takeF :: Integer -> DList a -> [a]
takeF 0 _ = []
takeF (n+1) (DLNode _ x next) = x : (takeF n next)


With the debugger I can see the calls that are made when I run:
 

takeF 2 (mkDList [1,2,3])

But I am more interested in seeing the expansion and reduction that the execution encounters as it lazily evaluates the function.


Daryoush


On Tue, Mar 31, 2009 at 6:49 PM, Bernie Pope <florbitous@gmail.com> wrote:
2009/4/1 Daryoush Mehrtash <dmehrtash@gmail.com>


I am trying to write out the execution of the recursive calls in mkDList example for different size lists.  Is there a way in ghc, or ghci where for a given list I can see the intermediate recursive and evaluation steps?

Have you tried stepping through the code using the GHCi debugger?

    http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html

If you have tried, but it didn't satisfy your needs, could you explain what is lacking?