Update for new extensible matching semantics

This commit is contained in:
Tony Garnock-Jones 2024-04-04 14:57:56 +02:00
parent 956f36c783
commit 83facdeee9
1 changed files with 11 additions and 6 deletions

View File

@ -22,14 +22,17 @@ Consider the pattern:
<arr [<lit 1> <bind <arr [<bind <_>> <_>]>> <_>]>
```
The following values each yield different results:
Each of the following values yields different results when matched against it:
- `[1 2 3]` fails, because `2` is not an array.
- `[1 [2 3] 4]` succeeds, yielding a binding sequence `[[2 3] 2]`, because the outer `bind`
captures the whole `[2 3]` array, and the inner (nested) `bind` captures the `2`.
- `[1 [2 3 4] 5]` fails, because `[2 3 4]` has more than the expected two elements.
- `[1 [2] 5]` fails, because `[2]` has fewer than the expected two elements.
- However, `[1 [2 3 4] 5]` succeeds, yielding a binding sequence `[[2 3 4] 2]`, because
`[2 3 4]` has *at least* the expected two elements.
- `[1 [<x> <y>] []]` succeeds, yielding a binding sequence `[[<x> <y>] <x>]`. Each discard
pattern (`<_>`) ignores the specific input it is given.
@ -95,11 +98,13 @@ If the type check fails, the pattern match fails. Otherwise, matching continues:
- `rec` patterns compare the label of the input Record against the `label` field in the
pattern; unless they match literally and exactly, the overall match fails. Otherwise, if the
number of fields in the input does not equal the number expected in the pattern, the match
fails. Otherwise, matching proceeds structurally recursively.
number of fields in the input is smaller than the number expected in the pattern, the match
fails. Otherwise, matching proceeds structurally recursively at each field specified in
the pattern. The pattern ignores fields present in the input but not mentioned in the pattern.
- `arr` patterns fail if the number of subpatterns does not match the number of items in the
input Sequence. Otherwise, matching proceeds structurally recursively.
- `arr` patterns fail if the number of subpatterns exceeds the number of items in the
input Sequence. Otherwise, matching proceeds structurally recursively at each item specified
in the pattern. The pattern ignores items present in the input but not mentioned in the pattern.
- `dict` patterns consider each of the key/subpattern pairs in `entries` in turn, according to
the Preserves order of the keys.[^dict-pattern-ordering] If any given key from the pattern