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 <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:error> "must have at least one element" mkDList xs = let (first,last <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:last>) = go last <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v: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 <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:last>) = go this xs next in (this,last <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:last>) takeF :: Integer <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t: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 <[email protected]> wrote: > 2009/4/1 Daryoush Mehrtash <[email protected]> > >> >> I am trying to write out the execution of the recursive calls in mkDList >> example<http:/http://www.haskell.org/haskellwiki/Tying_the_Knot/www.haskell.org/haskellwiki/Tying_the_Knot>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? >
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
