In order to support the behavior described in
PUP-4669 and for general flexibility we should allow a Struct's key to be specified by a Pattern type.
Where a Pattern key means 0 or infinite amount of occurrences,
an Optional around the pattern type means 0 or 1 occurrence, and an Array
specifies min, max occurrences.
- It is up to the user to construct the patterns so that they do not overlap. The struct type matches from left to right, the first pattern (if there are several) that accepts the key means that it is considered a match, and the count is associated with this struct entry. Thus, overlapping or keys with negative character set matches can cause ambiguities in the counts. This is the user's problem - it is impossible to issue a warning.
- Type Algebra on Structs with patterns:
- A struct is assignable to another if all after having matched all regular keys, regular keys in the RHS are matched by Pattern based keys on the LHS side, or if the set of Patterns are equal.
- Two structs with non equal patterns are disjunct