Skip to content

Commit 9d25695

Browse files
Docs: Remove section on typing rules for Match expr
That section was a preliminary descrition of what's implemented in this PR, and is essentially subsumed by the section on Dependent typing.
1 parent 0a73330 commit 9d25695

File tree

1 file changed

+0
-40
lines changed

1 file changed

+0
-40
lines changed

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -153,46 +153,6 @@ The third rule states that a match type conforms to its upper bound
153153

154154
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).
155155

156-
## Typing Rules for Match Expressions
157-
158-
Typing rules for match expressions are tricky. First, they need some new form of GADT matching for value parameters.
159-
Second, they have to account for the difference between sequential match on the term level and parallel match on the type level. As a running example consider:
160-
```scala
161-
type M[+X] = X match {
162-
case A => 1
163-
case B => 2
164-
}
165-
```
166-
We'd like to be able to typecheck
167-
```scala
168-
def m[X](x: X): M[X] = x match {
169-
case _: A => 1 // type error
170-
case _: B => 2 // type error
171-
}
172-
```
173-
Unfortunately, this goes nowhere. Let's try the first case. We have: `x.type <: A` and `x.type <: X`. This tells
174-
us nothing useful about `X`, so we cannot reduce `M` in order to show that the right hand side of the case is valid.
175-
176-
The following variant is more promising:
177-
```scala
178-
def m(x: Any): M[x.type] = x match {
179-
case _: A => 1
180-
case _: B => 2
181-
}
182-
```
183-
To make this work, we'd need a new form of GADT checking: If the scrutinee is a term variable `s`, we can make use of
184-
the fact that `s.type` must conform to the pattern's type and derive a GADT constraint from that. For the first case above,
185-
this would be the constraint `x.type <: A`. The new aspect here is that we need GADT constraints over singleton types where
186-
before we just had constraints over type parameters.
187-
188-
Assuming this extension, we can then try to typecheck as usual. E.g. to typecheck the first case `case _: A => 1` of the definition of `m` above, GADT matching will produce the constraint `x.type <: A`. Therefore, `M[x.type]` reduces to the singleton type `1`. The right hand side `1` of the case conforms to this type, so the case typechecks.
189-
190-
Typechecking the second case hits a snag, though. In general, the assumption `x.type <: B` is not enough to prove that
191-
`M[x.type]` reduces to `2`. However we can reduce `M[x.type]` to `2` if the types `A` and `B` do not overlap.
192-
So correspondence of match terms to match types is feasible only in the case of non-overlapping patterns (see next section about [overlapping patterns](#overlapping-patterns))
193-
194-
For simplicity, we have disregarded the `null` value in this discussion. `null` does not cause a fundamental problem but complicates things somewhat because some forms of patterns do not match `null`.
195-
196156
## Overlapping Patterns
197157

198158
A complete defininition of when two patterns or types overlap still needs to be worked out. Some examples we want to cover are:

0 commit comments

Comments
 (0)