<div class="gmail_quote">2012/1/8 Sergey Mironov <span dir="ltr"><<a href="mailto:ierton@gmail.com">ierton@gmail.com</a>></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 [''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) => </div><div> Zipper1 (Tree k a) -> 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'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'n'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 -> Tree k a :-> (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> => Zipper (Tree k a) (Tree k a) -> 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>