Data.Tree traversals

Dan Burton danburton.email at gmail.com
Tue Apr 21 04:08:00 UTC 2015


+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/20150420/5bed5890/attachment.html>


More information about the Libraries mailing list