An explicit form of pattern matching with match construction
Explicit match
construction in F# belongs to control flow elements, along with if-then-else
, or while-do
. Of other F# bits and pieces, a match
is a relatively complicated combination of the following parts and governing rules:
match comparison-expression with | pattern-expression1 -> result-expression1 ......................................... | pattern-expressionN -> result-expressionN
It works in this manner, that is, comparison-expression
is juxtaposed with each pattern-expression
beginning with pattern-expression1
and goes down the list until either the first match occurs, or passing pattern-expressionN
still non-matched. If a match is found for pattern-expressionX
, then the result of the entire construction is the result of result-expressionX
. If no matches are found, then MatchFailureException
is thrown, indicating that the match cases were incomplete.
The key points of pattern matching that are often missing...