shorthand `case` for if/else if chain

Dean Herington heringto@cs.unc.edu
Thu, 17 Jul 2003 14:50:30 -0400


I've thought for a while that it would be nice to have a shorthand for `if` /
`else if` chains.  For example:

  if a < b then "less"
  else if a == b then "equal"
  else "greater"

can be rendered with more structure as:

  case () of _ | a < b     -> "less"
               | a == b    -> "equal"
               | otherwise -> "greater"

but would look even nicer as:

  case | a < b     -> "less"
       | a == b    -> "equal"
       | otherwise -> "greater"

The shorthand just above requires a single addition to the Haskell grammar:

  exp10 -> `case` gdpat

with trivial translation to:

  `case` () `of` { _ gdpat }

-- Dean