Skip to content

Commit 8c022b9

Browse files
Docs: Remove mentions of overlapping patterns
This information is all outdated, the current implementation doesn't check for overlap between patterns. Instead it's looking at how the overlap between the scrutinee type and each pattern, sequentially.
1 parent 9d25695 commit 8c022b9

File tree

1 file changed

+0
-19
lines changed

1 file changed

+0
-19
lines changed

docs/docs/reference/new-types/match-types.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ if
118118
Match(S, C1, ..., Cn) can-reduce i, T
119119
```
120120
and, for `j` in `1..i-1`: `Cj` is disjoint from `Ci`, or else `S` cannot possibly match `Cj`.
121-
See the section on [overlapping patterns](#overlapping-patterns) for an elaboration of "disjoint" and "cannot possibly match".
122121

123122
## Subtyping Rules for Match Types
124123

@@ -153,22 +152,6 @@ The third rule states that a match type conforms to its upper bound
153152

154153
Within a match type `Match(S, Cs) <: B`, all occurrences of type variables count as covariant. By the nature of the cases `Ci` this means that occurrences in pattern position are contravarant (since patterns are represented as function type arguments).
155154

156-
## Overlapping Patterns
157-
158-
A complete defininition of when two patterns or types overlap still needs to be worked out. Some examples we want to cover are:
159-
160-
- Two classes overlap only if one is a subtype of the other
161-
- A final class `C` overlaps with a trait `T` only if `C` extends `T` directly or indirectly.
162-
- A class overlaps with a sealed trait `T` only if it overlaps with one of the known subclasses of `T`.
163-
- An abstract type or type parameter `A` overlaps with a type `B` only if `A`'s upper bound overlaps with `B`.
164-
- A union type `A1 | ... | An` overlaps with `B` only if at least one of `Ai` for `i` in `1..n` overlaps with `B`.
165-
- An intersection type `A1 & ... & An` overlaps with `B` only if all of `Ai` for `i` in `1..n` overlap with `B`.
166-
- If `C[X1, ..., Xn]` is a case class, then the instance type `C[A1, ..., An]` overlaps with the instance type `C[B1, ..., Bn]` only if for every index `i` in `1..n`,
167-
if `Xi` is the type of a parameter of the class, then `Ai` overlaps with `Bi`.
168-
169-
The last rule in particular is needed to detect non-overlaps for cases where the scrutinee and the patterns are tuples. I.e. `(Int, String)` does not overlap `(Int, Int)` since
170-
`String` does not overlap `Int`.
171-
172155
## Handling Termination
173156

174157
Match type definitions can be recursive, which raises the question whether and how to check
@@ -224,8 +207,6 @@ Match types have similarities with [closed type families](https://wiki.haskell.o
224207

225208
- Subtyping instead of type equalities.
226209
- Match type reduction does not tighten the underlying constraint, whereas type family reduction does unify. This difference in approach mirrors the difference between local type inference in Scala and global type inference in Haskell.
227-
- No a-priori requirement that cases are non-overlapping. Uses parallel reduction
228-
instead of always chosing a unique branch.
229210

230211
Match types are also similar to Typescript's [conditional types](https://github.com/Microsoft/TypeScript/pull/21316). The main differences here are:
231212

0 commit comments

Comments
 (0)