Hi Daryoush,<br><div class="gmail_quote"><br></div><div class="gmail_quote">You could add another case to label, importing Debug.Trace:</div><div class="gmail_quote"><br><font face="courier new, monospace">data Tree = Leaf | Node Tree Int Tree deriving Show<br>

<br><b>label t | trace (show $ &quot;label &quot; ++ show t) False = undefined</b><br></font><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

</blockquote></blockquote><font face="courier new, monospace">label (Node ln _ rn) ((h:r):rest) = (Node lr h rr, r:r2) where<br></font><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"></blockquote></blockquote><font face="courier new, monospace">                                        (lr, r1) = label ln rest<br>

</font><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

</blockquote></blockquote><font face="courier new, monospace">                                        (rr, r2) = label rn r1<br></font><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"></blockquote></blockquote><font face="courier new, monospace">label _ _  = (Leaf, [])<br>

</font><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

</blockquote></blockquote><font face="courier new, monospace">lt t = let (r, unused) = label t ([1..]:unused)<br>       in r</font></div><div><br></div><div>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.</div>

<br clear="all"><div>HTH,</div><div>Ozgur</div><div><br></div>