Skip to content

Commit a6d2312

Browse files
committed
doc(match-type): fix type lambda syntax
and mention that the typing rules are not yet defined
1 parent 61c342f commit a6d2312

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,21 @@ The third rule states that a match type conforms to its upper bound
124124

125125
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).
126126

127-
## Typing Rules for Match Expressions
127+
<!-- TODO revise this section, at least `S` has to be invariant according to the current implementation -->
128+
129+
## Future Typing Rules for Match Expressions
130+
131+
<!-- TODO document the final solution and remove `Future` from `Future Typing Rules...` -->
128132

129133
Typing rules for match expressions are tricky. First, they need some new form of GADT matching for value parameters.
130134
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:
131135
```scala
132-
type M[+X] = X match {
136+
type M[X] = X match {
133137
case A => 1
134138
case B => 2
135139
}
136140
```
137-
We'd like to be able to typecheck
141+
We would like to be able to typecheck
138142
```scala
139143
def m[X](x: X): M[X] = x match {
140144
case _: A => 1 // type error
@@ -144,14 +148,14 @@ def m[X](x: X): M[X] = x match {
144148
Unfortunately, this goes nowhere. Let's try the first case. We have: `x.type <: A` and `x.type <: X`. This tells
145149
us nothing useful about `X`, so we cannot reduce `M` in order to show that the right hand side of the case is valid.
146150

147-
The following variant is more promising:
151+
The following variant is more promising but does not compile either:
148152
```scala
149153
def m(x: Any): M[x.type] = x match {
150154
case _: A => 1
151155
case _: B => 2
152156
}
153157
```
154-
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
158+
To make this work, we would need a new form of GADT checking: If the scrutinee is a term variable `s`, we can make use of
155159
the fact that `s.type` must conform to the pattern's type and derive a GADT constraint from that. For the first case above,
156160
this would be the constraint `x.type <: A`. The new aspect here is that we need GADT constraints over singleton types where
157161
before we just had constraints over type parameters.

0 commit comments

Comments
 (0)