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
396
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
397
## Non-Value Types
383
398
384
399
The types explained in the following do not denote sets of values, nor do they appear explicitly in programs.
@@ -563,7 +578,6 @@ Equivalence ´(\equiv)´ between types is the smallest congruence [^congruence]
563
578
- corresponding parameters have equivalent types.
564
579
Note that the names of parameters do not matter for method type equivalence.
565
580
- 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
581
- 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
582
569
583
[^congruence]: A congruence is an equivalence relation which is closed under formation of contexts.
@@ -573,7 +587,7 @@ Equivalence ´(\equiv)´ between types is the smallest congruence [^congruence]
573
587
574
588
The conformance relation ´(<:)´ is the smallest transitive relation that satisfies the following conditions.
575
589
576
-
- Conformance includes equivalence. If `T \equiv U` then `T <: U`.
590
+
- Conformance includes equivalence. If ´T \equiv U´ then ´T <: U´.
577
591
- For every value type `T`, `scala.Nothing <: ´T´ <: scala.Any`.
578
592
- For every type constructor ´T´ (with any number of type parameters), `scala.Nothing <: ´T´ <: scala.Any`.
579
593
- For every value type ´T´, `scala.Null <: ´T´` unless `´T´ <: scala.AnyVal`.
@@ -582,10 +596,14 @@ The conformance relation ´(<:)´ is the smallest transitive relation that satis
582
596
- A singleton type `´p´.type` conforms to the type of the path ´p´.
583
597
- A singleton type `´p´.type` conforms to the type `scala.Singleton`.
584
598
- 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 \}´:
599
+
- 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
600
1. If the ´i´'th type parameter of ´T´ is declared covariant, then ´T_i <: U_i´.
587
601
1. If the ´i´'th type parameter of ´T´ is declared contravariant, then ´U_i <: T_i´.
588
602
1. If the ´i´'th type parameter of ´T´ is declared neither covariant nor contravariant, then ´U_i \equiv T_i´.
603
+
1. If ´U_i´ is a wildcard type argument of the form ´\\_ >: L <: U´, then ´T_i >: L´ and ´T_i <: U´.
604
+
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´.
605
+
1. If ´T_i´ is a wildcard type argument of the form ´\\_ >: L <: U´ and the ´i´'th type parameter is declared covariant, then ´U <: U_i´.
606
+
1. If ´T_i´ is a wildcard type argument of the form ´\\_ >: L <: U´ and the ´i´'th type parameter is declared contravariant, then ´L >: U_i´.
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