Proposal: Add a catamorphism on Trees

Daniel Wagner would like to add the following straightforward function to Data.Tree. I think this is a grand idea. foldTree :: (a -> [b] -> b) -> Tree a -> b foldTree f = go where go (Node x ts) = f x (map go ts)

Hi, Am Dienstag, den 17.05.2016, 17:03 -0400 schrieb David Feuer:
Daniel Wagner would like to add the following straightforward function to Data.Tree. I think this is a grand idea.
foldTree :: (a -> [b] -> b) -> Tree a -> b foldTree f = go where go (Node x ts) = f x (map go ts)
LGTM Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org

On Tue, 17 May 2016 17:03:31 -0400
David Feuer
Daniel Wagner would like to add the following straightforward function to Data.Tree. I think this is a grand idea.
foldTree :: (a -> [b] -> b) -> Tree a -> b foldTree f = go where go (Node x ts) = f x (map go ts)
+1 Nice, simple, and useful. -- Michael Walker (http://www.barrucadu.co.uk)

No objection here.
+1
On Tue, May 17, 2016 at 5:03 PM, David Feuer
Daniel Wagner would like to add the following straightforward function to Data.Tree. I think this is a grand idea.
foldTree :: (a -> [b] -> b) -> Tree a -> b foldTree f = go where go (Node x ts) = f x (map go ts) _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

+1, have implemented it in a few occasions already.
On Tue, May 17, 2016 at 11:03 PM, David Feuer
Daniel Wagner would like to add the following straightforward function to Data.Tree. I think this is a grand idea.
foldTree :: (a -> [b] -> b) -> Tree a -> b foldTree f = go where go (Node x ts) = f x (map go ts) _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-- Alp Mestanogullari

+1 from me as well. I think I'm unlikely to ever turn down a
straightforward catamorphism or anamorphism.
On Wed, May 18, 2016, 8:52 AM Alp Mestanogullari
+1, have implemented it in a few occasions already.
On Tue, May 17, 2016 at 11:03 PM, David Feuer
wrote: Daniel Wagner would like to add the following straightforward function to Data.Tree. I think this is a grand idea.
foldTree :: (a -> [b] -> b) -> Tree a -> b foldTree f = go where go (Node x ts) = f x (map go ts) _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-- Alp Mestanogullari _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

+1 Tom
El 18 may 2016, a las 08:55, Jake McArthur
escribió: +1 from me as well. I think I'm unlikely to ever turn down a straightforward catamorphism or anamorphism.
On Wed, May 18, 2016, 8:52 AM Alp Mestanogullari
wrote: +1, have implemented it in a few occasions already. On Tue, May 17, 2016 at 11:03 PM, David Feuer
wrote: Daniel Wagner would like to add the following straightforward function to Data.Tree. I think this is a grand idea. foldTree :: (a -> [b] -> b) -> Tree a -> b foldTree f = go where go (Node x ts) = f x (map go ts) _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-- Alp Mestanogullari _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

I was just thinking about refactoring some code to a tree fold—I had
assumed it was in the library already, and only realized it wasn't when I
saw this thread.
Definite +1.
On May 18, 2016 8:28 AM,
+1
Tom
El 18 may 2016, a las 08:55, Jake McArthur
escribió: +1 from me as well. I think I'm unlikely to ever turn down a straightforward catamorphism or anamorphism.
On Wed, May 18, 2016, 8:52 AM Alp Mestanogullari
wrote: +1, have implemented it in a few occasions already.
On Tue, May 17, 2016 at 11:03 PM, David Feuer
wrote: Daniel Wagner would like to add the following straightforward function to Data.Tree. I think this is a grand idea.
foldTree :: (a -> [b] -> b) -> Tree a -> b foldTree f = go where go (Node x ts) = f x (map go ts) _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-- Alp Mestanogullari _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries

Interestingly, I just noticed I'm missing a similar combinator in `free`
for the Cofree comonad.
https://github.com/ekmett/free/issues/136
On Wed, May 18, 2016 at 11:32 AM, Tikhon Jelvis
I was just thinking about refactoring some code to a tree fold—I had assumed it was in the library already, and only realized it wasn't when I saw this thread.
Definite +1. On May 18, 2016 8:28 AM,
wrote: +1
Tom
El 18 may 2016, a las 08:55, Jake McArthur
escribió: +1 from me as well. I think I'm unlikely to ever turn down a straightforward catamorphism or anamorphism.
On Wed, May 18, 2016, 8:52 AM Alp Mestanogullari
wrote: +1, have implemented it in a few occasions already.
On Tue, May 17, 2016 at 11:03 PM, David Feuer
wrote: Daniel Wagner would like to add the following straightforward function to Data.Tree. I think this is a grand idea.
foldTree :: (a -> [b] -> b) -> Tree a -> b foldTree f = go where go (Node x ts) = f x (map go ts) _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
-- Alp Mestanogullari _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
participants (9)
-
Alp Mestanogullari
-
amindfv@gmail.com
-
David Feuer
-
Edward Kmett
-
Jake McArthur
-
Joachim Breitner
-
John Wiegley
-
Michael Walker
-
Tikhon Jelvis