Skip to content

Commit 04a52b7

Browse files
committed
Merge branch 'travissarles-master' of github.com:scala/scala.github.com into travissarles-master
2 parents 66422f2 + 3d5de87 commit 04a52b7

File tree

6 files changed

+27
-25
lines changed

6 files changed

+27
-25
lines changed

conduct.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
<body>
77
<h2>Redirecting you to the Scala Code of Conduct...</h2>
88
<script type="text/javascript">
9-
window.location.replace('http://scala-lang.org/conduct.html');
9+
window.location.replace('http://scala-lang.org/conduct/');
1010
</script>
1111
</body>

overviews/collections/arrays.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,24 @@ The `evenElems` method returns a new array that consist of all elements of the a
7676
val arr = new Array[T]((arr.length + 1) / 2)
7777
^
7878

79-
What's required here is that you help the compiler out by providing some runtime hint what the actual type parameter of `evenElems` is. This runtime hint takes the form of a class manifest of type `scala.reflect.ClassManifest`. A class manifest is a type descriptor object which describes what the top-level class of a type is. Alternatively to class manifests there are also full manifests of type `scala.reflect.Manifest`, which describe all aspects of a type. But for array creation, only class manifests are needed.
79+
What's required here is that you help the compiler out by providing some runtime hint what the actual type parameter of `evenElems` is. This runtime hint takes the form of a class manifest of type `scala.reflect.ClassTag`. A class manifest is a type descriptor object which describes what the top-level class of a type is. Alternatively to class manifests there are also full manifests of type `scala.reflect.Manifest`, which describe all aspects of a type. But for array creation, only class manifests are needed.
8080

8181
The Scala compiler will construct class manifests automatically if you instruct it to do so. "Instructing" means that you demand a class manifest as an implicit parameter, like this:
82+
83+
def evenElems[T](xs: Vector[T])(implicit m: ClassTag[T]): Array[T] = ...
8284

83-
def evenElems[T](xs: Vector[T])(implicit m: ClassManifest[T]): Array[T] = ...
84-
85-
Using an alternative and shorter syntax, you can also demand that the type comes with a class manifest by using a context bound. This means following the type with a colon and the class name `ClassManifest`, like this:
85+
Using an alternative and shorter syntax, you can also demand that the type comes with a class manifest by using a context bound. This means following the type with a colon and the class name `ClassTag`, like this:
8686

87+
import scala.reflect.ClassTag
8788
// this works
88-
def evenElems[T: ClassManifest](xs: Vector[T]): Array[T] = {
89+
def evenElems[T: ClassTag](xs: Vector[T]): Array[T] = {
8990
val arr = new Array[T]((xs.length + 1) / 2)
9091
for (i <- 0 until xs.length by 2)
9192
arr(i / 2) = xs(i)
9293
arr
9394
}
9495

95-
The two revised versions of `evenElems` mean exactly the same. What happens in either case is that when the `Array[T]` is constructed, the compiler will look for a class manifest for the type parameter T, that is, it will look for an implicit value of type `ClassManifest[T]`. If such a value is found, the manifest is used to construct the right kind of array. Otherwise, you'll see an error message like the one above.
96+
The two revised versions of `evenElems` mean exactly the same. What happens in either case is that when the `Array[T]` is constructed, the compiler will look for a class manifest for the type parameter T, that is, it will look for an implicit value of type `ClassTag[T]`. If such a value is found, the manifest is used to construct the right kind of array. Otherwise, you'll see an error message like the one above.
9697

9798
Here is some REPL interaction that uses the `evenElems` method.
9899

@@ -104,15 +105,15 @@ Here is some REPL interaction that uses the `evenElems` method.
104105
In both cases, the Scala compiler automatically constructed a class manifest for the element type (first, `Int`, then `String`) and passed it to the implicit parameter of the `evenElems` method. The compiler can do that for all concrete types, but not if the argument is itself another type parameter without its class manifest. For instance, the following fails:
105106

106107
scala> def wrap[U](xs: Vector[U]) = evenElems(xs)
107-
<console>:6: error: No ClassManifest available for U.
108+
<console>:6: error: No ClassTag available for U.
108109
def wrap[U](xs: Vector[U]) = evenElems(xs)
109110
^
110111

111112
What happened here is that the `evenElems` demands a class manifest for the type parameter `U`, but none was found. The solution in this case is, of course, to demand another implicit class manifest for `U`. So the following works:
112113

113-
scala> def wrap[U: ClassManifest](xs: Vector[U]) = evenElems(xs)
114-
wrap: [U](xs: Vector[U])(implicit evidence$1: ClassManifest[U])Array[U]
114+
scala> def wrap[U: ClassTag](xs: Vector[U]) = evenElems(xs)
115+
wrap: [U](xs: Vector[U])(implicit evidence$1: scala.reflect.ClassTag[U])Array[U]
115116

116-
This example also shows that the context bound in the definition of `U` is just a shorthand for an implicit parameter named here `evidence$1` of type `ClassManifest[U]`.
117+
This example also shows that the context bound in the definition of `U` is just a shorthand for an implicit parameter named here `evidence$1` of type `ClassTag[U]`.
117118

118-
In summary, generic array creation demands class manifests. So whenever creating an array of a type parameter `T`, you also need to provide an implicit class manifest for `T`. The easiest way to do this is to declare the type parameter with a `ClassManifest` context bound, as in `[T: ClassManifest]`.
119+
In summary, generic array creation demands class manifests. So whenever creating an array of a type parameter `T`, you also need to provide an implicit class manifest for `T`. The easiest way to do this is to declare the type parameter with a `ClassTag` context bound, as in `[T: ClassTag]`.

sips/pending/_posts/2017-01-13-binary-compatibility.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
layout: inner-page-no-masthead
3-
title: SIP XX - Improving binary compatibility with @stableABI
2+
layout: sip
3+
title: SIP-NN - Improving binary compatibility with @stableABI
44
discourse: true
55
---
66

sips/sip-submission.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ a SIP or needs more work.
7676
After receiving the green light from the Process Lead, you can write up your
7777
idea and submit it as a SIP.
7878

79-
A SIP is a Markdown document written in conformance with the [process template](https://github.com/scala/slip/blob/master/slip-template.md).
79+
A SIP is a Markdown document written in conformance with the [process template](https://github.com/scala/scala.github.com/blob/master/sips/sip-template.md).
8080
It ought to contain a clear specification of the proposed changes. When such
8181
changes significantly alter the compiler internals, the author is invited to
8282
provide a proof of concept. Delivering a basic implementation can speed up the

tutorials/tour/_posts/2017-02-13-variances.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Fortunately, the compiler stops us long before we could get this far.
135135

136136
### Other Examples
137137

138-
Another example that can help one understand variance is `trait Function1[-T, R]` from the Scala standard library. `Function1` represents a function with one argument, where the first type parameter `T` represents the argument type, and the second type parameter `R` represents the return type. A `Function1` is contravariant over its argument type, and covariant over its return type. For this example we'll use the literal notation `A => B` to represent a `Function1[A, B]`.
138+
Another example that can help one understand variance is `trait Function1[-T, +R]` from the Scala standard library. `Function1` represents a function with one argument, where the first type parameter `T` represents the argument type, and the second type parameter `R` represents the return type. A `Function1` is contravariant over its argument type, and covariant over its return type. For this example we'll use the literal notation `A => B` to represent a `Function1[A, B]`.
139139

140140
Assume the similar `Cat`, `Dog`, `Animal` inheritance tree used earlier, plus the following:
141141

zh-cn/overviews/collections/arrays.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ num: 10
99
language: zh-cn
1010
---
1111

12-
在Scala中,[数组](http://www.scala-lang.org/api/2.10.0/scala/Array.html)是一种特殊的collection。一方面,Scala数组与Java数组是一一对应的。即Scala数组Array[Int]可看作Java的Int[],Array[Double]可看作Java的double[],以及Array[String]可看作Java的String[]。但Scala数组比Java数组提供了更多内容。首先,Scala数组是一种泛型。即可以定义一个Array[T],T可以是一种类型参数或抽象类型。其次,Scala数组与Scala序列是兼容的 - 在需要Seq[T]的地方可由Array[T]代替。最后,Scala数组支持所有的序列操作。这里有个实际的例子:
12+
在Scala中,[数组](http://www.scala-lang.org/api/{{ site.scala-version }}/scala/Array.html)是一种特殊的collection。一方面,Scala数组与Java数组是一一对应的。即Scala数组Array[Int]可看作Java的Int[],Array[Double]可看作Java的double[],以及Array[String]可看作Java的String[]。但Scala数组比Java数组提供了更多内容。首先,Scala数组是一种泛型。即可以定义一个Array[T],T可以是一种类型参数或抽象类型。其次,Scala数组与Scala序列是兼容的 - 在需要Seq[T]的地方可由Array[T]代替。最后,Scala数组支持所有的序列操作。这里有个实际的例子:
1313

1414
scala> val a1 = Array(1, 2, 3)
1515
a1: Array[Int] = Array(1, 2, 3)
@@ -76,16 +76,17 @@ evenElems方法返回一个新数组,该数组包含了参数向量xs的所有
7676
val arr = new Array[T]((arr.length + 1) / 2)
7777
^
7878

79-
这里需要你做的就是通过提供一些运行时的实际元素类型参数的线索来帮助编译器处理。这个运行时的提示采取的形式是一个`scala.reflect.ClassManifest`类型的类声明。一个类声明就是一个类型描述对象,给对象描述了一个类型的顶层类。另外,类声明也有`scala.reflect.Manifest`类型的所有声明,它描述了类型的各个方面。但对于数组创建而言,只需要提供类声明。
79+
这里需要你做的就是通过提供一些运行时的实际元素类型参数的线索来帮助编译器处理。这个运行时的提示采取的形式是一个`scala.reflect.ClassTag`类型的类声明。一个类声明就是一个类型描述对象,给对象描述了一个类型的顶层类。另外,类声明也有`scala.reflect.Manifest`类型的所有声明,它描述了类型的各个方面。但对于数组创建而言,只需要提供类声明。
8080

8181
如果你指示编译器那么做它就会自动的构建类声明。“指示”意味着你决定一个类声明作为隐式参数,像这样:
8282

83-
def evenElems[T](xs: Vector[T])(implicit m: ClassManifest[T]): Array[T] = ...
83+
def evenElems[T](xs: Vector[T])(implicit m: ClassTag[T]): Array[T] = ...
8484

8585
使用一个替换和较短的语法。通过用一个上下文绑定你也可以要求类型与一个类声明一起。这种方式是跟在一个冒号类型和类名为ClassManifest的后面,想这样:
8686

87+
import scala.reflect.ClassTag
8788
// this works
88-
def evenElems[T: ClassManifest](xs: Vector[T]): Array[T] = {
89+
def evenElems[T: ClassTag](xs: Vector[T]): Array[T] = {
8990
val arr = new Array[T]((xs.length + 1) / 2)
9091
for (i <- 0 until xs.length by 2)
9192
arr(i / 2) = xs(i)
@@ -104,16 +105,16 @@ evenElems方法返回一个新数组,该数组包含了参数向量xs的所有
104105
在这两种情况下,Scala编译器自动的为元素类型构建一个类声明(首先,Int,然后String)并且通过它传递evenElems 方法的隐式参数。编译器可以对所有的具体类型构造,但如果论点本身是另一个没有类声明的类型参数就不可以。例如,下面的错误:
105106

106107
scala> def wrap[U](xs: Vector[U]) = evenElems(xs)
107-
<console>:6: error: No ClassManifest available for U.
108+
<console>:6: error: No ClassTag available for U.
108109
def wrap[U](xs: Vector[U]) = evenElems(xs)
109110
^
110111

111112
这里所发生的是,evenElems 需要一个类型参数U的类声明,但是没有发现。这种情况下的解决方案是,当然,是为了U的另一个隐式类声明。所以下面起作用了:
112113

113-
scala> def wrap[U: ClassManifest](xs: Vector[U]) = evenElems(xs)
114-
wrap: [U](xs: Vector[U])(implicit evidence$1: ClassManifest[U])Array[U]
114+
scala> def wrap[U: ClassTag](xs: Vector[U]) = evenElems(xs)
115+
wrap: [U](xs: Vector[U])(implicit evidence$1: scala.reflect.ClassTag[U])Array[U]
115116

116-
这个实例还显示在定义U的上下文绑定里这仅是一个简短的隐式参数命名为`ClassManifest[U]`类型的`evidence$1`
117+
这个实例还显示在定义U的上下文绑定里这仅是一个简短的隐式参数命名为`ClassTag[U]`类型的`evidence$1`
117118

118-
总结,泛型数组创建需要类声明。所以每当创建一个类型参数T的数组,你还需要提供一个T的隐式类声明。最简单的方法是声明类型参数与ClassManifest的上下文绑定,如 `[T: ClassManifest]`
119+
总结,泛型数组创建需要类声明。所以每当创建一个类型参数T的数组,你还需要提供一个T的隐式类声明。最简单的方法是声明类型参数与ClassManifest的上下文绑定,如 `[T: ClassTag]`
119120

0 commit comments

Comments
 (0)