Advanced Patterns
Here are some additional pattern forms that are useful:
p1 | ... | pn
: an "or" pattern; matching against it succeeds if a match succeeds against any of the individual patternspi
, which are tried in order from left to right. All the patterns must bind the same variables.(p : t)
: a pattern with an explicit type annotation.c
: here,c
means any constant, such as integer literals, string literals, and booleans.'ch1'..'ch2'
: here,ch
means a character literal. For example,'A'..'Z'
matches any uppercase letter.p when e
: matchesp
but only ife
evaluates totrue
.
You can read about all the pattern forms in the manual.