<div class="gmail_quote">2012/1/8 Sergey Mironov <span dir="ltr">&lt;<a href="mailto:ierton@gmail.com">ierton@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi list!<div>Could you please give me a quick example of navigating throw Data.Typeable.Zipper built on top of a Rose Tree? </div><div>eg. (See ??? in the last line - is my question)</div><div><br></div><div><div>{-#LANGUAGE TemplateHaskell, DeriveDataTypeable, TypeOperators #-}</div>

<div><br></div><div>import Data.Typeable.Zipper</div><div><br></div><div>data Tree k a = Tree {</div><div>    _rules :: [(k,Tree k a)]</div><div>    } deriving(Show, Typeable)</div><div><br></div><div>$(mkLabelsNoTypes [&#39;&#39;Tree])</div>

<div><br></div><div>atree = Tree [(1, Tree []), (2, Tree []), (3, Tree [(11, Tree [])])]</div><div><br></div><div>moveToLeftmostChild :: (Typeable k, Typeable a) =&gt; </div><div>    Zipper1 (Tree k a) -&gt; Zipper1 (Tree k a)</div>

<div>moveToLeftmostChild z = moveTo ??? z</div></div><div><br></div><div>Thanks, </div><span class="HOEnZb"><font color="#888888"><div>Sergey</div>
</font></span></blockquote></div><br><div>Heh, look like I&#39;ve found the solution by myself! Here is the missing part:</div><div><br></div><div><div>get_child n t = ((_rules t) !! n) -- fast&#39;n&#39;diry</div><div>set_child n c t = t{ _rules = (hs ++ (c:ts)) } where</div>
<div>    (hs,ts) = splitAt n (_rules t)</div><div><br></div><div>focus_child :: Int -&gt; Tree k a :-&gt; (k, Tree k a)</div><div>focus_child n = lens (get_child n) (set_child n)</div><div><br></div><div>moveToLeftmostChild :: (Ord k, Typeable k, Typeable a) </div>
<div>    =&gt; Zipper (Tree k a) (Tree k a) -&gt; Zipper (Tree k a) (k, Tree k a)</div><div>moveToLeftmostChild z = moveTo (focus_child 0) z</div></div><div><br></div><div>Thanks,<br>Sergey</div>