haskell-issues
haskell-issues copied to clipboard
"Eta-reduce" case matches
There should be something that allows you to replace
case a of
B c -> d c
E _ -> f
with:
case a of
B -> d
E _ -> f
Can you provide an example where the benefit of that notation would be more clear?
I think I'd find this very confusing as a reader. Particulary when the various case patterns then appear to have different types.
evaluateMyLanguage :: Fix MyLanguage -> Int
evaluateMyLanguage = cata $ \case
Literal i -> i
Add x y -> x + y
Mul x y -> x * y
vs.
evaluateMyLanguage :: Fix MyLanguage -> Int
evaluateMyLanguage = cata $ \case
Literal -> id
Add -> (+)
Mul -> (*)
. It's also closer to each datatype's catamorphism (maybe for Maybe, bool for Bool, foldr for [], etc.)