There's a Glasgow extension that gets you to this:

treeFold :: (a -> a -> a) -> Tree a -> a
treeFold f = \case
  Leaf {} ->  id
  Node {} -> f `on` treeFold f

Or maybe this if parens are needed:

treeFold :: (a -> a -> a) -> Tree a -> a
treeFold f = \case
  (Leaf {}) ->  id
  (Node {}) -> f `on` treeFold f

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to