Active Patterns
Active Patterns are conceptually similar to discriminated unions. What really changes is how they are used, not the syntax.
By definition, it can be said that an active pattern is a set of called partitions used to compare the input data. Also, these partitions (labels) can be used in expression
.
This is the syntax:
let (|identifer1|identifier2|...|) [ arguments ] = expression let (|identifier|_|) [ arguments ] = expression
As we can see in the preceding code lines, there are two different implementations. They are as follows:
- Complete Active Patterns: They are described in the first row and all the labels are explicitly denominated. They must be a maximum of seven and each one must have a result return.
- Partial Active Patterns: It is similar, but one's choice must be the wildcard operator
|_|
seen previously. This operator is used to define all the cases in which the input must not be partitioned.
The main example to understand how to use the action pattern is as follows...