|
118 | 118 | Match(S, C1, ..., Cn) can-reduce i, T
|
119 | 119 | ```
|
120 | 120 | 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". |
122 | 121 |
|
123 | 122 | ## Subtyping Rules for Match Types
|
124 | 123 |
|
@@ -153,22 +152,6 @@ The third rule states that a match type conforms to its upper bound
|
153 | 152 |
|
154 | 153 | 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).
|
155 | 154 |
|
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 |
| - |
172 | 155 | ## Handling Termination
|
173 | 156 |
|
174 | 157 | 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
|
224 | 207 |
|
225 | 208 | - Subtyping instead of type equalities.
|
226 | 209 | - 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. |
229 | 210 |
|
230 | 211 | Match types are also similar to Typescript's [conditional types](https://github.com/Microsoft/TypeScript/pull/21316). The main differences here are:
|
231 | 212 |
|
|
0 commit comments