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/_spec/03-types.md
+19-3Lines changed: 19 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -173,7 +173,7 @@ In a sequence of consecutive type infix operations ´t_0 \, \mathit{op} \, t_1 \
173
173
If they are all left-associative, the sequence is interpreted as ´(... (t_0 \mathit{op_1} t_1) \mathit{op_2} ...) \mathit{op_n} t_n´, otherwise it is interpreted as ´t_0 \mathit{op_1} (t_1 \mathit{op_2} ( ... \mathit{op_n} t_n) ...)´.
174
174
175
175
The type operators `|` and `&` are not really special.
176
-
Nevertheless, unless shadowed, they resolve to `scala.|` and `scala.&`, which represent [union and intersection types](#union-and-intersection-types), respectively.
176
+
Nevertheless, unless shadowed, they resolve to [the fundamental type aliases `scala.|` and `scala.&`](./12-the-scala-standard-library.html#fundamental-type-aliases), which represent [union and intersection types](#union-and-intersection-types), respectively.
177
177
178
178
### Function Types
179
179
@@ -230,6 +230,21 @@ scala.PolyFunction {
230
230
}
231
231
```
232
232
233
+
### Tuple Types
234
+
235
+
```ebnf
236
+
SimpleType1 ::= ...
237
+
| ‘(’ TypesOrWildcards ‘)’
238
+
```
239
+
240
+
A _tuple type_ ´(T_1, ..., T_n)´ where ´n \geq 2´ is sugar for the type `´T_1´ *: ... *: ´T_n´ *: scala.EmptyTuple`, which is itself a series of nested infix types which are sugar for `*:[´T_1´, *:[´T_2´, ... *[´T_n´, scala.EmptyTuple]]]`.
241
+
The ´T_i´ can be wildcard type arguments.
242
+
243
+
Notes:
244
+
245
+
-`(´T_1´)` is the type ´T_1´, and not `´T_1´ *: scala.EmptyTuple` (´T_1´ cannot be a wildcard type argument in that case).
246
+
-`()` is not a valid type (not even `scala.EmptyTuple`).
247
+
233
248
### Concrete Refined Types
234
249
235
250
```ebnf
@@ -285,7 +300,7 @@ _Types_ are either _proper types_, _type constructors_ or _poly-kinded types_.
285
300
286
301
All types live in a single lattice with respect to a [_conformance_](#conformance) relationship ´<:´.
287
302
The _top type_ is `AnyKind` and the _bottom type_ is `Nothing`: all types conform to `AnyKind`, and `Nothing` conforms to all types.
288
-
They can be referred to as the standard library entities`scala.AnyKind` and `scala.Nothing`, respectively.
303
+
They can be referred to with [the fundamental type aliases`scala.AnyKind` and `scala.Nothing`](./12-the-scala-standard-library.html#fundamental-type-aliases), respectively.
289
304
290
305
Types can be _concrete_ or _abstract_.
291
306
An abstract type ´T´ always has lower and upper bounds ´L´ and ´H´ such that ´L >: T´ and ´T <: H´.
@@ -1080,7 +1095,7 @@ Note that the conditions are not all mutually exclusive.
1080
1095
- ´S_i´ and ´T_i´ are types and ´S_i =:= T_i´, or
1081
1096
- ´S_i´ is a type and ´T_i´ is a wildcard type argument of the form ´? >: L_2 <: H_2´ and ´L_2 <: S_i´ and ´S_i <: H_2´, or
1082
1097
- ´S_i´ is a wildcard type argument of the form ´? >: L_1 <: H_1´ and ´T_i´ is a wildcard type argument of the form ´? >: L_2 <: H_2´ and ´L_2 <: L_1´ and ´H_1 <: H_2´ (i.e., the ´S_i´ "interval" is contained in the ´T_i´ "interval").
1083
-
- ´T = q.C[T_1, ..., T_n]´ with ´n \geq 0´ and `baseType(´S´, ´C´)` is defined and `baseType(´S´, ´C´) ´<: T´.
1098
+
- ´T = q.C[T_1, ..., T_n]´ with ´n \geq 0´ and `baseType(´S´, ´C´)` is defined and `baseType(´S´, ´C´) ´<: T´`.
1084
1099
- ´S = p.X[S_1, ..., S_n]´ and ´p.X´ is non-class type designator and ´H <: T´ where ´H´ is the upper bound of the underlying type definition of ´p.X´.
1085
1100
- ´S = p.C´ and `´T = C´.this` and ´C´ is the hidden class of an `object` and:
1086
1101
- ´p = \epsilon´ or ´p´ is a package ref, or
@@ -1123,6 +1138,7 @@ Note that the conditions are not all mutually exclusive.
1123
1138
- ´S´ is a stable type and ´T = q.x´ is a term designator with underlying type ´T_1´ and ´T_1´ is a stable type and ´S <: T_1´.
1124
1139
-`´S = S_1´ { ´R´ }` and ´S_1 <: T´.
1125
1140
-`´S =´ { ´\alpha´ => ´S_1´ }` and ´S_1 <: T´.
1141
+
-`´T =´ scala.Tuple´_n[T_1, ..., T_n]´` with ´1 \leq n \leq 22´, and `´S <: T_1´ *: ... *: ´T_n´ *: scala.EmptyTuple`.
1126
1142
1127
1143
We define `isSubPrefix(´p´, ´q´)` where ´p´ and ´q´ are prefixes as:
Copy file name to clipboardExpand all lines: docs/_spec/12-the-scala-standard-library.md
+64-32Lines changed: 64 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -12,10 +12,23 @@ Some of these classes are described in the following.
12
12

13
13
14
14
<!-- TODO: Briefly mention scala.deprecated somewhere, and link to [deprecated page](./A%3F-deprecated.md) -->
15
+
16
+
## Fundamental Type Aliases
17
+
18
+
The `scala` package provides the following fundamental type aliases, which expose to user code some forms of [types](./03-types.html) that cannot otherwise be written:
19
+
20
+
```scala
21
+
typeAnyKind= ´x´ // where ´x´ is the internal AnyKind type
22
+
typeNothing= ´x´ // where ´x´ is the internal Nothing type
23
+
type|= [A, B] =>>A ´|´ B// where | is the internal union type operator
24
+
type&= [A, B] =>>A ´&´ B// where & is the internal intersection type operator
25
+
```
26
+
15
27
## Root Classes
16
28
17
-
The root of this hierarchy is formed by class `Any`.
29
+
The root of this hierarchy is formed by class `scala.Any`.
18
30
Every class in a Scala execution environment inherits directly or indirectly from this class.
31
+
By definition, `Any` is also the top [proper type](./03-types.html#proper-types).
19
32
Class `Any` has two direct subclasses: `AnyRef` and `AnyVal`.
20
33
21
34
The subclass `AnyRef` represents all values which are represented as objects in the underlying host system.
@@ -304,42 +317,42 @@ case class Tuple´n´[+T_1, ..., +T_n](_1: T_1, ..., _´n´: T_´n´) {
304
317
-->
305
318
### The `Function` Classes
306
319
307
-
For each class type `Function´n´` where ´n = 0, ..., 22´, Scala defines the following function class:
320
+
For each natural ´n \geq 0´, the `scala` package defines the following function class:
308
321
309
322
```scala
310
323
packagescala
311
324
traitFunction´_n´[-´T_1´, ..., -´T_n´, +´R´]:
312
325
defapply(´x_1´: ´T_1´, ..., ´x_n´: ´T_n´): ´R´
313
-
overridedeftoString="<function´_n´>"
314
-
defcurried: ´T_1´ => ... => ´T_n´ =>R= ...
315
-
deftupled: ((´T_1´, ..., ´T_n´)) =>R= ...
316
326
```
317
327
318
-
For function types `Function´n´` where ´n > 22´, Scala defines a unique function class:
328
+
These classes participate in the desugaring of [concrete function types](./03-types.html#function-types).
319
329
330
+
For values of ´n \leq 22´, the `Function´_n´` classes define additional methods:
320
331
```scala
321
332
packagescala
322
-
traitFunctionXXL:
323
-
defapply(xs: IArray[Object]):Object
324
-
overridedeftoString="<functionXXL>"
333
+
traitFunction´_n´[-´T_1´, ..., -´T_n´, +´R´]:
334
+
...
335
+
overridedeftoString="<function´_n´>"
336
+
defcurried: ´T_1´ => ... => ´T_n´ =>R= ...
337
+
deftupled: ((´T_1´, ..., ´T_n´)) =>R= ...
325
338
```
326
339
327
-
There is no loss of type safety, as the internal representation is still `Function´n´` for all ´n´.
328
-
However this means methods `curried` and `tupled` are not available on functions with more than 22 parameters.
329
-
330
340
The implicitly imported [`Predef`](#the-predef-object) object defines the name
331
341
`Function` as an alias of `Function1`.
332
342
333
-
<!-- TODO: Remove below ? -->
334
343
The `PartialFunction` subclass of `Function1` represents functions that (indirectly) specify their domain.
335
344
Use the `isDefined` method to query whether the partial function is defined for a given input (i.e., whether the input is part of the function's domain).
`PartialFunction` participates in the desugaring of [pattern matching anonymous functions](08-pattern-matching.html#pattern-matching-anonymous-functions).
355
+
343
356
### Trait `Product`
344
357
<!-- TODO: Move somewhere else ? -->
345
358
<!-- TODO: Could not find more info on which non-Product methods case class automatically define -->
@@ -351,36 +364,55 @@ All enum definitions automatically extend the `reflect.Enum` trait (and generate
351
364
352
365
### Tuple Classes
353
366
354
-
Tuple classes are case classes whose fields can be accessed using selectors `_1`, ..., `_n`.
355
-
Their functionality is abstracted in the corresponding `scala.Product_´n´` trait.
356
-
The _n_-ary tuple class and product trait are defined at least as follows in the standard Scala library (they might also add other methods and implement other traits).
367
+
Tuples are a form of _HLists_ defined by the following classes:
A _tuple type_ ´(T_1, ..., T_n)´ where ´n \geq 2´ is an alias for the type `´T_1´ *: ... *: ´T_n´ *: scala.EmptyTuple`.
400
+
For ´1 \leq n \leq 22´, the concrete implementations of `*:` are instances of `Tuple´_n´` classes, which also implement corresponding `Product´_n´` traits.
401
+
They are defined at least as follows in the standard Scala library (they might also add other methods and implement other traits).
If ´n \leq 22´, the type `´T_1´ *: ... *: ´T_n´ *: scala.EmptyTuple` is both a subtype and a supertype of tuple class `scala.Tuple´_n´[´T_1´, ..., ´T_n´]`.
415
+
For ´n > 22´, the concrete implementations of ´*:´ are instances of implementation-specific private classes.
0 commit comments