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
A _parameterized type_ ´T[ T_1, ..., T_n ]´ consists of a type designator ´T´ and type parameters ´T_1, ..., T_n´ where ´n \geq 1´.
162
+
A _parameterized type_ ´T[ T_1, ..., T_n ]´ consists of a type designator ´T´ and type arguments ´T_1, ..., T_n´ where ´n \geq 1´.
167
163
´T´ must refer to a type constructor which takes ´n´ type parameters ´a_1, ..., a_n´.
168
164
165
+
<!-- TODO Mention well-kinded conformance when we introduce kind-polymorphism -->
169
166
Say the type parameters have lower bounds ´L_1, ..., L_n´ and upper bounds ´U_1, ..., U_n´.
170
-
The parameterized type is well-formed if each actual type parameter_conforms to its bounds_, i.e. ´\sigma L_i <: T_i <: \sigma U_i´ where ´\sigma´ is the substitution ´[ a_1 := T_1, ..., a_n := T_n ]´.
167
+
The parameterized type is well-formed if each type argument_conforms to its bounds_, i.e. ´\sigma L_i <: T_i <: \sigma U_i´ where ´\sigma´ is the substitution ´[ a_1 := T_1, ..., a_n := T_n ]´.
Their exact supertype and implementation can be consulted in the [function classes section](./12-the-scala-standard-library.md#the-function-classes) of the standard library page in this document.
357
397
358
-
#### Wildcard Types
359
-
360
-
```ebnf
361
-
WildcardType ::= ‘_’ TypeBounds
362
-
```
363
-
<!-- TODO: Update this to use new mechanism -->
364
-
A _wildcard type_ is of the form `_´\;´>:´\,L\,´<:´\,U´`.
365
-
Both bound clauses may be omitted.
366
-
If a lower bound clause `>:´\,L´` is missing, `>:´\,´scala.Nothing` is assumed.
367
-
If an upper bound clause `<:´\,U´` is missing, `<:´\,´scala.Any` is assumed.
368
-
A wildcard type is a shorthand for an existentially quantified type variable, where the existential quantification is implicit.
369
-
370
-
A wildcard type must appear as a type argument of a parameterized type.
371
-
Let ´T = p.c[\mathit{targs},T,\mathit{targs}']´ be a parameterized type where ´\mathit{targs}, \mathit{targs}'´ may be empty and ´T´ is a wildcard type `_´\ ´>:´\,L\,´<:´\,U´`.
372
-
Then ´T´ is equivalent to the existential type
373
-
374
-
```scala
375
-
´p.c[\mathit{targs},t,\mathit{targs}']´ forSome { type ´t´ >: ´L´ <: ´U´ }
376
-
```
377
-
378
-
where ´t´ is some fresh type variable.
379
-
Wildcard types may also appear as parts of [infix types](#infix-types), [function types](#function-types), or [tuple types](#tuple-types).
380
-
Their expansion is then the expansion in the equivalent parameterized type.
381
-
382
398
## Non-Value Types
383
399
384
400
The types explained in the following do not denote sets of values, nor do they appear explicitly in programs.
@@ -563,7 +579,6 @@ Equivalence ´(\equiv)´ between types is the smallest congruence [^congruence]
563
579
- corresponding parameters have equivalent types.
564
580
Note that the names of parameters do not matter for method type equivalence.
565
581
- Two [polymorphic method types](#polymorphic-method-types) are equivalent if they have the same number of type parameters, and, after renaming one set of type parameters by another, the result types as well as lower and upper bounds of corresponding type parameters are equivalent.
566
-
- Two [existential types](#existential-types) are equivalent if they have the same number of quantifiers, and, after renaming one list of type quantifiers by another, the quantified types as well as lower and upper bounds of corresponding quantifiers are equivalent.
567
582
- Two [type constructors](#type-constructors) are equivalent if they have the same number of type parameters, and, after renaming one list of type parameters by another, the result types as well as variances, lower and upper bounds of corresponding type parameters are equivalent.
568
583
569
584
[^congruence]: A congruence is an equivalence relation which is closed under formation of contexts.
@@ -573,7 +588,7 @@ Equivalence ´(\equiv)´ between types is the smallest congruence [^congruence]
573
588
574
589
The conformance relation ´(<:)´ is the smallest transitive relation that satisfies the following conditions.
575
590
576
-
- Conformance includes equivalence. If `T \equiv U` then `T <: U`.
591
+
- Conformance includes equivalence. If ´T \equiv U´ then ´T <: U´.
577
592
- For every value type `T`, `scala.Nothing <: ´T´ <: scala.Any`.
578
593
- For every type constructor ´T´ (with any number of type parameters), `scala.Nothing <: ´T´ <: scala.Any`.
579
594
- For every value type ´T´, `scala.Null <: ´T´` unless `´T´ <: scala.AnyVal`.
@@ -582,10 +597,13 @@ The conformance relation ´(<:)´ is the smallest transitive relation that satis
582
597
- A singleton type `´p´.type` conforms to the type of the path ´p´.
583
598
- A singleton type `´p´.type` conforms to the type `scala.Singleton`.
584
599
- A type projection `´T´#´t´` conforms to `´U´#´t´` if ´T´ conforms to ´U´.
585
-
- A parameterized type `´T´[´T_1´, ..., ´T_n´]` conforms to `´T´[´U_1´, ..., ´U_n´]` if the following three conditions hold for ´i \in \{ 1, ..., n \}´:
600
+
- A parameterized type `´T´[´T_1´, ..., ´T_n´]` conforms to `´T´[´U_1´, ..., ´U_n´]` if the following conditions hold for ´i \in \{ 1, ..., n \}´:
586
601
1. If the ´i´'th type parameter of ´T´ is declared covariant, then ´T_i <: U_i´.
587
602
1. If the ´i´'th type parameter of ´T´ is declared contravariant, then ´U_i <: T_i´.
588
603
1. If the ´i´'th type parameter of ´T´ is declared neither covariant nor contravariant, then ´U_i \equiv T_i´.
604
+
1. If ´U_i´ is a wildcard type argument of the form ´\\_ >: L <: U´, then ´T_i >: L´ and ´T_i <: U´.
605
+
1. If ´U_i´ is a wildcard type argument of the form ´\\_ >: L_1 <: U_1´ and ´T_i´ is a wildcard argument of the form ´\\_ >: L_2 <: U_2´, then ´L_1 <: L_2´ and ´H_2 <: H_1´.
606
+
1. If ´U_i´ is a wildcard type argument of the form ´\\_ >: L <: U´ and the ´i´'th type parameter is declared covariant, then
589
607
- A compound type `´T_1´ with ... with ´T_n´ {´R\,´}` conforms to each of its component types ´T_i´.
590
608
- If ´T <: U_i´ for ´i \in \{ 1, ..., n \}´ and for every binding ´d´ of a type or value ´x´ in ´R´ there exists a member binding of ´x´ in ´T´ which subsumes ´d´, then ´T´ conforms to the compound type `´U_1´ with ... with ´U_n´ {´R\,´}`.
591
609
- If ´T_i \equiv T_i'´ for ´i \in \{ 1, ..., n\}´ and ´U´ conforms to ´U'´ then the method type ´(p_1:T_1, ..., p_n:T_n) U´ conforms to ´(p_1':T_1', ..., p_n':T_n') U'´.
0 commit comments