i&#39;m sorry, the example with the flip list would be<div><br></div><div>flipList [[1,2],[3,4]] ==[4,3,2,1]<br><br><div class="gmail_quote">On Mon, Aug 30, 2010 at 10:54 PM, Carter Schonwald <span dir="ltr">&lt;<a href="mailto:carter.schonwald@gmail.com">carter.schonwald@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello All, <div>In the course of some code I&#39;ve been working on, I found I needed generic foldl  / foldr over heterogeneous data structures, where I can easily pick whether I want top down left right, botom up left right,  and  ___  right left traversals, and to in tandem sensibly approach if a parent node should be included altogether</div>


<div><br></div><div>What i&#39;m wondering is if i&#39;m somehow overlooking some simpler ways of writing such or if my attached code for the foldl case (the foldr analogue is easy to see from the example code).</div><div>


<br></div><div>code with example  follows</div><div><br></div><div>--- my &quot;foldl&quot; that is abstracted from traversal order</div><div><div>travL :: (b -&gt; a -&gt; b)-&gt; </div><div>        GenericQ (Maybe  a) -&gt; </div>


<div>        (Maybe a -&gt; b  -&gt;(b -&gt; a -&gt; b)-&gt;(b-&gt;b)-&gt; b) -&gt; </div><div>        GenericQ (b -&gt;b)</div><div>travL f  qry merge x nil = merge (qry x) nil f (\nl-&gt; </div><div>                                                foldl (flip ($)) nl  $ gmapQ (travL f qry merge) x )</div>


<div><br></div><div>--travR could be written as</div><div>--- travR f  qry merge x nil = foldl (flip f) nil $ travL  (flip (:)) qry merge x [] </div><div><br></div><div>-- example usage</div><div>-- takes the integers in some datastructure, and puts them in a list</div>


<div>-- example: </div><div>flipList :: Data a =&gt; a -&gt; [Integer]</div><div>flipList x = travL (flip (:) )  (mkQ Nothing  (Just :: Integer -&gt; Maybe Integer)  ) (\ v nl f k -&gt; maybe  (k nl) (\y -&gt; k $! f nl y)  v ) x []</div>


</div><div><br></div><div><br></div><div>I suppose that i could simplify it to </div><div><br></div><div>travL :: GenericQ (Maybe  a) -&gt;  </div><div>        (Maybe a -&gt; b  -&gt;(b-&gt;b)-&gt; b) -&gt; </div>
<div>        GenericQ (b -&gt;b) </div><div><br></div><div>and have the operand <b>f</b> of the fold work within the <b>merge</b> parameter, but that doesn&#39;t address the important bit in my mind,</div><div>namely that while its pretty clear to me that I can write the <b>synthesize</b> and <b>everything</b> combinators using my &quot;travL/R&quot; stuff, its not clear to me that the converse or something close to it is the case.</div>


<div><br></div><div>Anyways, what&#39;re everyone&#39;s thoughts?</div><div>thanks!</div><div>-Carter</div>
</blockquote></div><br></div>