Partial application in case expression rules

Occasionally I find it would be nice to be able to omit some or all constructor parameters from a pattern matching rule. Perhaps the compiler could put them in for you and apply them to the right hand side of the rule ? data Tree a = Leaf a| Node (Tree a) (Tree a) treeFold :: (a -> a -> a) -> Tree a -> a treeFold f = \case Leaf -> id Node -> f `on` treeFold f This could be desugared at some point to treeFold f = \case Leaf a -> id a Node a b -> (f `on` treeFold f) a b I suppose such an extension has been considered before, but I could not find such a discussion. (In http://haskell.1045720.n5.nabble.com/Partial-pattern-matching-td3087200.html the thread focused instead on case expressions over functions) Any pointers to previous discussions ? Comments ? Thank you! Patrick Prémont

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

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
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

On Mon, Nov 5, 2012 at 4:15 PM, Stephen Tetley
There is a long extant GHC extension to elide constructor arguments
f (Leaf {}) = ...
f (Node {}) = ...
I don't think that's an extension, it falls out directly from how Haskell builds records on top of ADTs and is specified in the standard as such. See http://www.haskell.org/onlinereport/decls.html at the end of the "Labelled Fields" section for Haskell98, or the middle of section 3.15.2 in http://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-490003.15... the H'2010 version. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix/linux, openafs, kerberos, infrastructure http://sinenomine.net
participants (3)
-
Brandon Allbery
-
Patrick Premont
-
Stephen Tetley