Is there a tool to see reduction steps?

I have been given a piece of code that uses Tie-ing the Knot concept to label a tree of nodes in breath first manner. It seems to work fine, but I am having trouble expanding the code on my own to see the evaluation process. I like to know if there is a tools to use to see the reduction steps.
data Tree = Leaf | Node Tree Int Tree deriving Show
label (Node ln _ rn) ((h:r):rest) = (Node lr h rr, r:r2) where (lr, r1) = label ln rest (rr, r2) = label rn r1 label _ _ = (Leaf, []) lt t = let (r, unused) = label t ([1..]:unused) in r
-- Daryoush Weblog: http://onfp.blogspot.com/

Hi Daryoush, You could add another case to label, importing Debug.Trace: data Tree = Leaf | Node Tree Int Tree deriving Show *label t | trace (show $ "label " ++ show t) False = undefined*
label (Node ln _ rn) ((h:r):rest) = (Node lr h rr, r:r2) where
(lr, r1) = label ln rest
(rr, r2) = label rn r1
label _ _ = (Leaf, [])
lt t = let (r, unused) = label t ([1..]:unused) in r
This will output one line per each call to label. Except for one thing: your show function will never actually terminate, if the tree is cyclic. You can fix this by defining your own show function. HTH, Ozgur

There is Hood [11 and its graphical front-end GHood [2]. I have never used them myself however, only seen them demonstrated. Normally, using Debug.Trace is enough for me. [1] http://www.ittc.ku.edu/csdl/fpg/Tools/Hood [2] http://community.haskell.org/~claus/GHood/ Thomas Am 10.10.2012 22:53, schrieb Daryoush Mehrtash:
I have been given a piece of code that uses Tie-ing the Knot concept to label a tree of nodes in breath first manner. It seems to work fine, but I am having trouble expanding the code on my own to see the evaluation process. I like to know if there is a tools to use to see the reduction steps.
data Tree = Leaf | Node Tree Int Tree deriving Show
label (Node ln _ rn) ((h:r):rest) = (Node lr h rr, r:r2) where (lr, r1) = label ln rest (rr, r2) = label rn r1 label _ _ = (Leaf, []) lt t = let (r, unused) = label t ([1..]:unused) in r
-- Daryoush
Weblog: http://onfp.blogspot.com/
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Daryoush Mehrtash
-
Ozgur Akgun
-
Thomas Horstmeyer