aelve / haskell-issues

An unofficial issue tracker for all things Haskell-related
18 stars 0 forks source link

"Eta-reduce" case matches #38

Open Gurkenglas opened 8 years ago

Gurkenglas commented 8 years ago

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
sjakobi commented 7 years ago

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.

Gurkenglas commented 7 years ago
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.)