Data.Tree traversals

David Feuer david.feuer at gmail.com
Tue Apr 21 04:50:31 UTC 2015


Er... I may have mixed up preorder and depth-first -- I tend to do that.
The point is, whatever it doesn't do, it should do.

On Tue, Apr 21, 2015 at 12:08 AM, Dan Burton <danburton.email at gmail.com>
wrote:

> +1 I don't see why not. Pre-order and post-order are also pretty textbook
> traversals. I don't imagine they'll be used very heavily, but they're
> certainly good for learning purposes.
>
> Perhaps instead of newtypes for each of these, we can just provide the
> corresponding "traverse" function. These types unsurprisingly correspond to
> lens's Traversal (Tree a) (Tree b) a b.
>
> depthFirst :: Applicative f => (a -> f b) -> Tree a -> f (Tree b)
> depthFirst = ...
>
> preOrder :: Applicative f => (a -> f b) -> Tree a -> f (Tree b)
> preOrder = ...
>
> postOrder :: Applicative f => (a -> f b) -> Tree a -> f (Tree b)
> postOrder = ...
>
> inOrder :: Applicative f => (a -> f b) -> Tree a -> f (Tree b)
> inOrder = traverse
>
> -- Dan Burton
>
> On Mon, Apr 20, 2015 at 8:20 PM, David Feuer <david.feuer at gmail.com>
> wrote:
>
>> Data.Tree makes Tree into a Traversable in only one way: depth-first. It
>> seems to me that we should have a newtype to traverse in breadth-first
>> order.
>>
>> David Feuer
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150421/5b6b3141/attachment.html>


More information about the Libraries mailing list