i'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"><<a href="mailto:carter.schonwald@gmail.com">carter.schonwald@gmail.com</a>></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'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'm wondering is if i'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 "foldl" that is abstracted from traversal order</div><div><div>travL :: (b -> a -> b)-> </div><div> GenericQ (Maybe a) -> </div>
<div> (Maybe a -> b ->(b -> a -> b)->(b->b)-> b) -> </div><div> GenericQ (b ->b)</div><div>travL f qry merge x nil = merge (qry x) nil f (\nl-> </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 => a -> [Integer]</div><div>flipList x = travL (flip (:) ) (mkQ Nothing (Just :: Integer -> Maybe Integer) ) (\ v nl f k -> maybe (k nl) (\y -> 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) -> </div><div> (Maybe a -> b ->(b->b)-> b) -> </div>
<div> GenericQ (b ->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'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 "travL/R" stuff, its not clear to me that the converse or something close to it is the case.</div>
<div><br></div><div>Anyways, what're everyone's thoughts?</div><div>thanks!</div><div>-Carter</div>
</blockquote></div><br></div>