6 Nov
2012
6 Nov
'12
5:15 a.m.
Whoops - replied in haste... There is a long extant GHC extension to elide constructor arguments f (Leaf {}) = ... f (Node {}) = ... There is a recent extension for "lambda case" which you were also using and I didn't look closely at. On 5 November 2012 21:11, Stephen Tetley <stephen.tetley@gmail.com> wrote:
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