You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/reference/new-types/match-types.md
+17-9Lines changed: 17 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -85,12 +85,12 @@ is `Match(S, C1, ..., Cn) <: B` where each case `Ci` is of the form
85
85
```
86
86
[Xs] => P => T
87
87
```
88
+
88
89
Here, `[Xs]` is a type parameter clause of the variables bound in pattern `Pi`. If there are no bound type variables in a case, the type parameter clause is omitted and only the function type `P => T` is kept. So each case is either a unary function type or a type lambda over a unary function type.
89
90
90
91
`B` is the declared upper bound of the match type, or `Any` if no such bound is given.
91
92
We will leave it out in places where it does not matter for the discussion. Scrutinee, bound and pattern types must be first-order types.
92
93
93
-
94
94
## Match type reduction
95
95
96
96
Match type reduction follows the semantics of match expression, that is, a match type of the form `S match { P1 => T1 ... Pn => Tn }` reduces to `Ti` if and only if `s: S match { _: P1 => T1 ... _: Pn => Tn }` evaluates to a value of type `Ti` for all `s: S`.
@@ -115,28 +115,36 @@ Disjointness proofs rely on the following properties of Scala types:
115
115
The following rules apply to match types. For simplicity, we omit environments and constraints.
116
116
117
117
The first rule is a structural comparison between two match types:
118
+
118
119
```
119
-
Match(S, C1, ..., Cm) <: Match(T, D1, ..., Dn)
120
+
S match { P1 => T1 ... Pm => Tm } <: T match { Q1 => U1 ... Qn => Un }
120
121
```
122
+
121
123
if
124
+
122
125
```
123
-
S <: T, m >= n, Ci <: Di for i in 1..n
126
+
S =:= T, m >= n, Pi =:= Qi and Ti <: Qi for i in 1..n
124
127
```
125
-
I.e. scrutinees and corresponding cases must be subtypes, no case re-ordering is allowed, but the subtype can have more cases than the supertype.
128
+
129
+
I.e. scrutinees and patterns must be equal and the corresponding bodies must be subtypes. No case re-ordering is allowed, but the subtype can have more cases than the supertype.
126
130
127
131
The second rule states that a match type and its redux are mutual subtypes
132
+
128
133
```
129
-
Match(S, Cs) <: T
130
-
T <: Match(S, Cs)
134
+
S match { P1 => T1 ... Pn => Tn } <: U
135
+
U <: S match { P1 => T1 ... Pn => Tn }
131
136
```
137
+
132
138
if
139
+
133
140
```
134
-
Match(S, Cs) reduces-to T
141
+
S match { P1 => T1 ... Pn => Tn } reduces-to U
135
142
```
136
143
137
-
The third rule states that a match type conforms to its upper bound
144
+
The third rule states that a match type conforms to its upper bound:
0 commit comments