Proposal: improve the Data.Tree API

João Cristóvão jmacristovao at gmail.com
Mon Feb 24 10:55:59 UTC 2014


I was thinking of:

length :: Tree a -> Int
length = L.length . flatten

But to be honest, I don't have strong feelings about this, I'm willing to
drop this particular function (length) from the proposal, if there is no
consensus.

João


2014-02-24 10:50 GMT+00:00 Ivan Lazar Miljenovic <ivan.miljenovic at gmail.com>
:

> On 24 February 2014 21:39, João Cristóvão <jmacristovao at gmail.com> wrote:
> > Hello,
> >
> > The Data.Tree API seems rather poor. Some research on hackage shows some
> > additional functions being defined in very unrelated packages:
> >
> >
> http://hackage.haskell.org/package/debian-3.81/docs/Debian-Apt-Dependencies.html#g:3
> >
> >
> http://hackage.haskell.org/package/hledger-lib-0.22.1/docs/Hledger-Utils.html#v:subtreeat
> >
> > I propose the addition of the following functions, that seem rather
> straigh
> > forward to me:
> >
> > -- | get the sub-tree rooted at the first (left-most, depth-first)
> > occurrence
> > -- of the specified node value
> > lookupTree :: Eq a => a -> Tree a -> Maybe (Tree a)
> >
> > -- | get the sub-tree rooted at the first (left-most, depth-first) value
> > that
> > -- matches the provided condition
> > findTree :: (a -> Bool) -> Tree a -> Maybe (Tree a)
> >
> > -- | keep only the elements that match the provided condition
> > filter :: (a -> Bool) -> Tree a -> Tree a
> >
> > The 'Tree' is appended in the name, to distinguish from the Foldable
> > instances, that return the value, and not a sub-tree.
> >
> > Additionally, the following two functions might also be useful (even if
> the
> > implementation is very simple in the second case):
> > -- | get the sub-tree for the specified node value in the first tree in
> > -- forest in which it occurs.
> > lookupTreeInForest :: Eq a => a -> [Tree a] -> Maybe (Tree a)
> >
> > -- | Length of the tree
> > length :: Tree a -> Int
>
> What is the length of a tree?  The number of sub-trees of that
> particular root node?  The overall width of the tree?  The number of
> nodes?
>
> >
> > There are probably more useful functions to add, so suggestions are
> > welcomed.
> >
> > Previous discussion:
> > https://github.com/haskell/containers/issues/39#issuecomment-35799628
> >
> > Discussion period: 2 weeks
> >
> > Cheers,
> > João
> >
> > _______________________________________________
> > Libraries mailing list
> > Libraries at haskell.org
> > http://www.haskell.org/mailman/listinfo/libraries
> >
>
>
>
> --
> Ivan Lazar Miljenovic
> Ivan.Miljenovic at gmail.com
> http://IvanMiljenovic.wordpress.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140224/11f11a74/attachment.html>


More information about the Libraries mailing list