diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/03-types.md | 4 | ||||
-rw-r--r-- | spec/04-basic-declarations-and-definitions.md | 4 | ||||
-rw-r--r-- | spec/05-classes-and-objects.md | 20 | ||||
-rw-r--r-- | spec/06-expressions.md | 13 | ||||
-rw-r--r-- | spec/07-implicits.md | 6 |
5 files changed, 25 insertions, 22 deletions
diff --git a/spec/03-types.md b/spec/03-types.md index d2f41daabf..a3167646ca 100644 --- a/spec/03-types.md +++ b/spec/03-types.md @@ -507,7 +507,7 @@ Assume the class definitions ```scala class Ref[T] -abstract class Outer { type T } . +abstract class Outer { type T } ``` Here are some examples of existential types: @@ -530,7 +530,7 @@ Ref[_ <: java.lang.Number] The type `List[List[_]]` is equivalent to the existential type ```scala -List[List[t] forSome { type t }] . +List[List[t] forSome { type t }] ``` ###### Example diff --git a/spec/04-basic-declarations-and-definitions.md b/spec/04-basic-declarations-and-definitions.md index c4d3425fff..5e055228f1 100644 --- a/spec/04-basic-declarations-and-definitions.md +++ b/spec/04-basic-declarations-and-definitions.md @@ -91,7 +91,7 @@ expands to ```scala case object Red extends Color case object Green extends Color -case object Blue extends Color . +case object Blue extends Color ``` --> @@ -144,7 +144,7 @@ value definition `val $p$ = $e$` is expanded as follows: val $\$ x$ = $e$ match {case $p$ => ($x_1 , \ldots , x_n$)} val $x_1$ = $\$ x$._1 $\ldots$ -val $x_n$ = $\$ x$._n . +val $x_n$ = $\$ x$._n ``` Here, $\$ x$ is a fresh name. diff --git a/spec/05-classes-and-objects.md b/spec/05-classes-and-objects.md index 5bd520589d..ffb65979f7 100644 --- a/spec/05-classes-and-objects.md +++ b/spec/05-classes-and-objects.md @@ -854,9 +854,8 @@ a `val` or `var` modifier. Hence, an accessor definition for the parameter is [generated](#class-definitions). A case class definition of `$c$[$\mathit{tps}\,$]($\mathit{ps}_1\,$)$\ldots$($\mathit{ps}_n$)` with type -parameters $\mathit{tps}$ and value parameters $\mathit{ps}$ implicitly -generates an [extractor object](08-pattern-matching.html#extractor-patterns) which is -defined as follows: +parameters $\mathit{tps}$ and value parameters $\mathit{ps}$ implies +the definition of a companion object, which serves as an [extractor object](08-pattern-matching.html#extractor-patterns). It has the following shape: ```scala object $c$ { @@ -873,11 +872,13 @@ each $\mathit{xs}\_i$ denotes the parameter names of the parameter section $\mathit{ps}\_i$, and $\mathit{xs}\_{11}, \ldots , \mathit{xs}\_{1k}$ denote the names of all parameters in the first parameter section $\mathit{xs}\_1$. -If a type parameter section is missing in the -class, it is also missing in the `apply` and -`unapply` methods. -The definition of `apply` is omitted if class $c$ is -`abstract`. +If a type parameter section is missing in the class, it is also missing in the `apply` and `unapply` methods. + +If the companion object $c$ is already defined, +the `apply` and `unapply` methods are added to the existing object. +If the object $c$ already has a [matching](#definition-matching) +`apply` (or `unapply`) member, no new definition is added. +The definition of `apply` is omitted if class $c$ is `abstract`. If the case class definition contains an empty value parameter list, the `unapply` method returns a `Boolean` instead of an `Option` type and @@ -890,9 +891,6 @@ def unapply[$\mathit{tps}\,$]($x$: $c$[$\mathit{tps}\,$]) = x ne null The name of the `unapply` method is changed to `unapplySeq` if the first parameter section $\mathit{ps}_1$ of $c$ ends in a [repeated parameter](04-basic-declarations-and-definitions.html#repeated-parameters). -If a companion object $c$ exists already, no new object is created, -but the `apply` and `unapply` methods are added to the existing -object instead. A method named `copy` is implicitly added to every case class unless the class already has a member (directly defined or inherited) with that name, or the diff --git a/spec/06-expressions.md b/spec/06-expressions.md index 581170c5f9..9e49dfa199 100644 --- a/spec/06-expressions.md +++ b/spec/06-expressions.md @@ -222,9 +222,14 @@ the linearization of class `D` is `{D, B, A, Root}`. Then we have: ```scala -(new A).superA == "Root", - (new C).superB = "Root", (new C).superC = "B", -(new D).superA == "Root", (new D).superB = "A", (new D).superD = "B", +(new A).superA == "Root" + +(new C).superB == "Root" +(new C).superC == "B" + +(new D).superA == "Root" +(new D).superB == "A" +(new D).superD == "B" ``` Note that the `superB` function returns different results @@ -455,7 +460,7 @@ $e$. Type applications can be omitted if [local type inference](#local-type-inference) can infer best type parameters -for a polymorphic functions from the types of the actual function arguments +for a polymorphic function from the types of the actual function arguments and the expected result type. ## Tuples diff --git a/spec/07-implicits.md b/spec/07-implicits.md index 662b653f71..b0c8c1da24 100644 --- a/spec/07-implicits.md +++ b/spec/07-implicits.md @@ -155,7 +155,7 @@ sort(yss) The call above will be completed by passing two nested implicit arguments: ```scala -sort(yss)(xs: List[Int] => list2ordered[Int](xs)(int2ordered)) . +sort(yss)(xs: List[Int] => list2ordered[Int](xs)(int2ordered)) ``` The possibility of passing implicit arguments to implicit arguments @@ -218,7 +218,7 @@ which implicit arguments are searched is ```scala List[List[Int]] => Ordered[List[List[Int]]], -List[Int] => Ordered[List[Int]] +List[Int] => Ordered[List[Int]], Int => Ordered[Int] ``` @@ -290,7 +290,7 @@ or the call-by-name category). Class `scala.Ordered[A]` contains a method ```scala - def <= [B >: A](that: B)(implicit b2ordered: B => Ordered[B]): Boolean . + def <= [B >: A](that: B)(implicit b2ordered: B => Ordered[B]): Boolean ``` Assume two lists `xs` and `ys` of type `List[Int]` |