[Haskell-cafe] Is there a tool to see reduction steps?

Ozgur Akgun ozgurakgun at gmail.com
Wed Oct 10 23:12:33 CEST 2012

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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121010/b2e48f08/attachment.htm>

More information about the Haskell-Cafe mailing list