
Jon Cast wrote:
On Wednesday 27 June 2007, Andrew Coppin wrote:
Wow, wait a sec - case expressions are allowed to have guards too??
Yes. I guess I assumed you knew that, sorry.
The only syntactic (or semantic) difference between function equations and case expressions (aside from the fact that case expressions require you to tuple up the values you're pattern-matching on) is the fact that case expressions use -> where function bindings use =. Other than that, the two forms are exactly equivalent.
I knew they were nearly identical. I didn't realise that they *were* identical! Hmm, I tried to find out 1 thing and actually found out 2 things! :-D I wonder what the layout for that is... something like this? case foo of patter1 | guard1 -> ... | guard2 -> ... pattern2 | guard3 -> ... | guard4 -> ... Well, I'll have to go try it... I always thought of guards as being a nice shorthand for if-expressions - but if they can affect the order of pattern matching, clearly they are more drastically different than I realised. (Generally, I never ever use 'em!)