|Version 1 (modified by simonmar@…, 8 years ago)|
Very often I find myself wanting to write an if-then-else with multiple branches. This is one expression form that isn't catered for well at the moment. Using nested 'if' is unsatisfactory because the nesting grows with each branch, and all those keywords are quite syntactically heavy.
One idiom that is often used for this is:
case () of _ | pred1 -> e1 ... | predn -> en
this is very powerful in conjunction with pattern guards, incedentally. But it's ugly. I propose a simpler form:
case | pred1 -> e1 ... | predn -> en
There are no syntactic problems with this because it is uniquely identified by the sequence 'case |' which is currently not a valid expression prefix in Haskell. It's therefore backwards compatible.
Semantics can be defined as shorthand for the original case statement above.
Cons: it isn't implemented anywhere.