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
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?If you have tried, but it didn't satisfy your needs, could you explain what is lacking?