
I am trying to write out the execution of the recursive calls in mkDList examplehttp:/http://www.haskell.org/haskellwiki/Tying_the_Knot/www.haskell.org/hask...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? thanks, Daryoush

2009/4/1 Daryoush Mehrtash
I am trying to write out the execution of the recursive calls in mkDList examplehttp:/http://www.haskell.org/haskellwiki/Tying_the_Knot/www.haskell.org/hask...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?

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:Intege...
-> 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
2009/4/1 Daryoush Mehrtash
I am trying to write out the execution of the recursive calls in mkDList examplehttp:/http://www.haskell.org/haskellwiki/Tying_the_Knot/www.haskell.org/hask...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?

Daryoush Mehrtash
But I am more interested in seeing the expansion and reduction that the execution encounters as it lazily evaluates the function.
Have you tried GHood? http://www.cs.kent.ac.uk/people/staff/cr3/toolbox/haskell/GHood/ It is a bit like the recently-released Vacuum visualiser for data structures, except that it also animates the reduction sequence. (Have a look at some of the online examples - you can view the reduction steps right there in your web browser.) Regards, Malcolm

But I am more interested in seeing the expansion and reduction that the execution encounters as it lazily evaluates the function.
Have you tried GHood?
examples:
http://www.cs.kent.ac.uk/people/staff/cr3/toolbox/haskell/GHood/
package: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/GHood
It is a bit like the recently-released Vacuum visualiser for data structures, except that it also animates the reduction sequence. (Have a look at some of the online examples - you can view the reduction steps right there in your web browser.)
Ahem. While I do recommend GHood for getting animated visual insights into what your program is doing, *GHood does not animate reductions* for instance, the steps of 'id id id ()' reducing will not be visible as such, though by observing the first 'id', you would be able to see all the 'id's being applied to their parameters and yielding their results (and you could add further probes) *GHood animates observations* - when the usage contexts starts looking through an observe probe for the data behind the probe (demand goes in) - when the data behind a probe has been reduced to produce a further level of WHNF (data goes out) Non-strict evaluation means that things won't be reduced unless that is forced by observation but, nevertheless, the two are not the same, they complement each other. Also, GHood/Hood do not observe sharing or when data is freed, which might be relevant for the example. On the positive side, observations can be targetted, so one can put small probes into large projects, and observations are very relevant for (relative) strictness issues. It would be nice if an animation visualizer could be built on top of Vacuum, just as GHood was built on top of Hood. Of course, I'd really like to be able to follow reductions textually as well, in a combination of editor/ide/GHCi. It was shown long ago that this needn't be in conflict with efficient implementation, such as compiled graph reduction (as I might have mentioned before;-). I doubt that the ancient code still installs properly, but the old pages or pi-RED/KiR are still there(*), so anyone building a new Haskell implementation could look at user's guide and papers for inspiration, but it would be difficult to add after the fact to an implementation as complex as GHC. Claus (*) http://www.informatik.uni-kiel.de/~base/
participants (4)
-
Bernie Pope
-
Claus Reinke
-
Daryoush Mehrtash
-
Malcolm Wallace