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: _includes/sidebar-toc-glossary.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,6 @@ <h5 class="contents">Terms</h5>
5
5
<divid="toc"></div>
6
6
</div>
7
7
<hr>
8
-
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{{ page.relative_path }}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
8
+
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{% if page.collection %}{{ page.relative_path }}{% else %}{{ page.path }}{% endif %}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{{ page.relative_path }}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
49
+
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{% if page.collection %}{{ page.relative_path }}{% else %}{{ page.path }}{% endif %}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{{ page.relative_path }}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
29
+
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{% if page.collection %}{{ page.relative_path }}{% else %}{{ page.path }}{% endif %}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{{ page.relative_path }}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
55
+
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{% if page.collection %}{{ page.relative_path }}{% else %}{{ page.path }}{% endif %}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{{ page.relative_path }}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
47
+
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{% if page.collection %}{{ page.relative_path }}{% else %}{{ page.path }}{% endif %}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{{ page.relative_path }}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
55
+
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{% if page.collection %}{{ page.relative_path }}{% else %}{{ page.path }}{% endif %}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
Copy file name to clipboardExpand all lines: _includes/tutorial-toc.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,6 @@ <h5>Contents</h5>
24
24
{% include tutorial-tour-list.txt %}
25
25
</div>
26
26
<hr>
27
-
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{{ page.relative_path }}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
27
+
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{% if page.collection %}{{ page.relative_path }}{% else %}{{ page.path }}{% endif %}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{{ page.relative_path }}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
29
+
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{% if page.collection %}{{ page.relative_path }}{% else %}{{ page.path }}{% endif %}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
Copy file name to clipboardExpand all lines: _layouts/sips.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ <h5 class="contents" style="margin-bottom: 0;">Writing a SIP</h5>
40
40
<li><ahref="{{ site.baseurl }}/sips/sip-submission.html">Submitting a SIP</a></li>
41
41
<li><ahref="{{ site.baseurl }}/sips/sip-tutorial.html">Tutorial: Writing a SIP</a></li>
42
42
</ul>
43
-
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{{ page.relative_path }}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
43
+
<divclass="help-us"><ahref="https://github.com/scala/docs.scala-lang/blob/master/{% if page.collection %}{{ page.relative_path }}{% else %}{{ page.path }}{% endif %}"><iclass="fa fa-pencil" aria-hidden="true"></i> Problem with this page?<br> Please help us fix it!</a></div>
Copy file name to clipboardExpand all lines: _overviews/collections/seqs.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,7 +74,7 @@ If a sequence is mutable, it offers in addition a side-effecting `update` method
74
74
|`xs union ys`|Multiset union; same as `xs ++ ys`.|
75
75
|`xs.distinct`|A subsequence of `xs` that contains no duplicated element.|
76
76
77
-
Trait [Seq](http://www.scala-lang.org/api/current/scala/collection/Seq.html) has two subtraits [LinearSeq](http://www.scala-lang.org/api/current/scala/collection/IndexedSeq.html), and [IndexedSeq](http://www.scala-lang.org/api/current/scala/collection/IndexedSeq.html). These do not add any new operations, but each offers different performance characteristics: A linear sequence has efficient `head` and `tail` operations, whereas an indexed sequence has efficient `apply`, `length`, and (if mutable) `update` operations. Frequently used linear sequences are `scala.collection.immutable.List` and `scala.collection.immutable.Stream`. Frequently used indexed sequences are `scala.Array` and `scala.collection.mutable.ArrayBuffer`. The `Vector` class provides an interesting compromise between indexed and linear access. It has both effectively constant time indexing overhead and constant time linear access overhead. Because of this, vectors are a good foundation for mixed access patterns where both indexed and linear accesses are used. You'll learn more on vectors [later](http://docs.scala-lang.org/overviews/collections/concrete-immutable-collection-classes.html#vectors).
77
+
Trait [Seq](http://www.scala-lang.org/api/current/scala/collection/Seq.html) has two subtraits [LinearSeq](http://www.scala-lang.org/api/current/scala/collection/IndexedSeq.html), and [IndexedSeq](http://www.scala-lang.org/api/current/scala/collection/IndexedSeq.html). These do not add any new operations, but each offers different performance characteristics: A linear sequence has efficient `head` and `tail` operations, whereas an indexed sequence has efficient `apply`, `length`, and (if mutable) `update` operations. Frequently used linear sequences are `scala.collection.immutable.List` and `scala.collection.immutable.Stream`. Frequently used indexed sequences are `scala.Array` and `scala.collection.mutable.ArrayBuffer`. The `Vector` class provides an interesting compromise between indexed and linear access. It has both effectively constant time indexing overhead and constant time linear access overhead. Because of this, vectors are a good foundation for mixed access patterns where both indexed and linear accesses are used. You'll learn more on vectors [later](concrete-immutable-collection-classes.html#vectors).
Copy file name to clipboardExpand all lines: _overviews/collections/sets.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,7 +107,7 @@ Comparing the two interactions shows an important principle. You often can repla
107
107
108
108
Mutable sets also provide add and remove as variants of `+=` and `-=`. The difference is that `add` and `remove` return a Boolean result indicating whether the operation had an effect on the set.
109
109
110
-
The current default implementation of a mutable set uses a hashtable to store the set's elements. The default implementation of an immutable set uses a representation that adapts to the number of elements of the set. An empty set is represented by just a singleton object. Sets of sizes up to four are represented by a single object that stores all elements as fields. Beyond that size, immutable sets are implemented as [hash tries](concrete-immutable-collection-classes.html#hash_tries).
110
+
The current default implementation of a mutable set uses a hashtable to store the set's elements. The default implementation of an immutable set uses a representation that adapts to the number of elements of the set. An empty set is represented by just a singleton object. Sets of sizes up to four are represented by a single object that stores all elements as fields. Beyond that size, immutable sets are implemented as [hash tries](concrete-immutable-collection-classes.html#hash-tries).
111
111
112
112
A consequence of these representation choices is that, for sets of small sizes (say up to 4), immutable sets are usually more compact and also more efficient than mutable sets. So, if you expect the size of a set to be small, try making it immutable.
Copy file name to clipboardExpand all lines: _overviews/macros/blackbox-whitebox.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ compehensibility.
35
35
36
36
However sometimes def macros transcend the notion of "just a regular method". For example, it is possible for a macro expansion to yield an expression of a type that is more specific than the return type of a macro. In Scala 2.10, such expansion will retain its precise type as highlighted in the ["Static return type of Scala macros"](http://stackoverflow.com/questions/13669974/static-return-type-of-scala-macros) article at Stack Overflow.
37
37
38
-
This curious feature provides additional flexibility, enabling [fake type providers](http://meta.plasm.us/posts/2013/07/11/fake-type-providers-part-2/), [extended vanilla materialization](/sips/pending/source-locations.html), [fundep materialization](/overviews/macros/implicits.html#fundep_materialization) and [extractor macros](https://github.com/scala/scala/commit/84a335916556cb0fe939d1c51f27d80d9cf980dc), but it also sacrifices clarity - both for humans and for machines.
38
+
This curious feature provides additional flexibility, enabling [fake type providers](http://meta.plasm.us/posts/2013/07/11/fake-type-providers-part-2/), [extended vanilla materialization](/sips/pending/source-locations.html), [fundep materialization](/overviews/macros/implicits.html#fundep-materialization) and [extractor macros](https://github.com/scala/scala/commit/84a335916556cb0fe939d1c51f27d80d9cf980dc), but it also sacrifices clarity - both for humans and for machines.
39
39
40
40
To concretize the crucial distinction between macros that behave just like normal methods and macros that refine their return types, we introduce the notions of blackbox macros and whitebox macros. Macros that faithfully follow their type signatures are called **blackbox macros** as their implementations are irrelevant to understanding their behaviour (could be treated as black boxes). Macros that can't have precise signatures in Scala's type system are called **whitebox macros** (whitebox def macros do have signatures, but these signatures are only approximations).
41
41
@@ -50,7 +50,7 @@ We express the distinction by replacing `scala.reflect.macros.Context` with `sca
50
50
Blackbox def macros are treated differently from def macros of Scala 2.10. The following restrictions are applied to them by the Scala typechecker:
51
51
52
52
1. When an application of a blackbox macro expands into tree `x`, the expansion is wrapped into a type ascription `(x: T)`, where `T` is the declared return type of the blackbox macro with type arguments and path dependencies applied in consistency with the particular macro application being expanded. This invalidates blackbox macros as an implementation vehicle of [type providers](http://meta.plasm.us/posts/2013/07/11/fake-type-providers-part-2/).
53
-
1. When an application of a blackbox macro still has undetermined type parameters after Scala's type inference algorithm has finished working, these type parameters are inferred forcedly, in exactly the same manner as type inference happens for normal methods. This makes it impossible for blackbox macros to influence type inference, prohibiting [fundep materialization](/overviews/macros/implicits.html#fundep_materialization).
53
+
1. When an application of a blackbox macro still has undetermined type parameters after Scala's type inference algorithm has finished working, these type parameters are inferred forcedly, in exactly the same manner as type inference happens for normal methods. This makes it impossible for blackbox macros to influence type inference, prohibiting [fundep materialization](/overviews/macros/implicits.html#fundep-materialization).
54
54
1. When an application of a blackbox macro is used as an implicit candidate, no expansion is performed until the macro is selected as the result of the implicit search. This makes it impossible to [dynamically calculate availability of implicit macros](/sips/rejected/source-locations.html).
55
55
1. When an application of a blackbox macro is used as an extractor in a pattern match, it triggers an unconditional compiler error, preventing [customizations of pattern matching](https://github.com/paulp/scala/commit/84a335916556cb0fe939d1c51f27d80d9cf980dc) implemented with macros.
Copy file name to clipboardExpand all lines: _overviews/macros/bundles.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ following reasons:
27
27
1. Being limited to functions makes modularizing complex macros awkward. It's quite typical to see macro logic concentrate in helper
28
28
traits outside macro implementations, turning implementations into trivial wrappers, which just instantiate and call helpers.
29
29
30
-
2. Moreover, since macro parameters are path-dependent on the macro context, [special incantations](/overviews/macros/overview.html#writing_bigger_macros) are required to wire implementations and helpers together.
30
+
2. Moreover, since macro parameters are path-dependent on the macro context, [special incantations](/overviews/macros/overview.html#writing-bigger-macros) are required to wire implementations and helpers together.
31
31
32
32
Macro bundles provide a solution to these problems by allowing macro implementations to be declared in classes that take
33
33
`c: scala.reflect.macros.blackbox.Context` or `c: scala.reflect.macros.whitebox.Context` as their constructor parameters, relieving macro implementations from having
Copy file name to clipboardExpand all lines: _overviews/macros/changelog211.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,21 +25,21 @@ Quasiquotes is the single most impressive upgrade for reflection and macros in S
25
25
26
26
### New macro powers
27
27
28
-
1)**[Fundep materialization](http://docs.scala-lang.org/overviews/macros/implicits.html#fundep_materialization)**. Since Scala 2.10.2, implicit whitebox macros can be used to materialize instances of type classes, however such materialized instances can't guide type inference. In Scala 2.11.0, materializers can also affect type inference, helping scalac to infer type arguments for enclosing method applications, something that's used with great success in Shapeless. Even more, with the fix of [SI-3346](https://issues.scala-lang.org/browse/SI-3346), this inference guiding capability can affect both normal methods and implicit conversions alike. Please note, however, that fundep materialization doesn't let one change how Scala's type inference works, but merely provides a way to throw more type constraints into the mix, so it's, for example, impossible to make type inference flow from right to left using fundep materializers.
28
+
1)**[Fundep materialization](implicits.html#fundep-materialization)**. Since Scala 2.10.2, implicit whitebox macros can be used to materialize instances of type classes, however such materialized instances can't guide type inference. In Scala 2.11.0, materializers can also affect type inference, helping scalac to infer type arguments for enclosing method applications, something that's used with great success in Shapeless. Even more, with the fix of [SI-3346](https://issues.scala-lang.org/browse/SI-3346), this inference guiding capability can affect both normal methods and implicit conversions alike. Please note, however, that fundep materialization doesn't let one change how Scala's type inference works, but merely provides a way to throw more type constraints into the mix, so it's, for example, impossible to make type inference flow from right to left using fundep materializers.
29
29
30
30
2)**[Extractor macros](https://github.com/paulp/scala/commit/84a335916556cb0fe939d1c51f27d80d9cf980dc)**. A prominent new feature in Scala 2.11.0 is [name-based extractors](https://github.com/scala/scala/pull/2848) implemented by Paul Phillips. And as usual, when there's a Scala feature, it's very likely that macros can make use of it. Indeed, with the help of structural types, whitebox macros can be used to write extractors than refine the types of extractees on case-by-case basis. This is the technique that we use internally to implement quasiquotes.
31
31
32
32
3)**[Named and default arguments in macros](https://github.com/scala/scala/pull/3543)**. This is something that strictly speaking shouldn't belong to this changelog, because this feature was reverted shortly after being merged into Scala 2.11.0-RC1 due to a tiny mistake that led to a regression, but we've got a patch that makes the macro engine understand named/default arguments in macro applications. Even though the code freeze won't let us bring this change in Scala 2.11.0, we expect to merge it in Scala 2.11.1 at an earliest opportunity.
33
33
34
-
4)**[Type macros](http://docs.scala-lang.org/overviews/macros/typemacros.html) and [macro annotations](http://docs.scala-lang.org/overviews/macros/annotations.html)**. Neither type macros, not macro annotations are included of Scala 2.11.0. It is highly unlikely that type macros will ever be included in Scala, but we still deliberate on macro annotations. However, macro annotations are available both for Scala 2.10.x and for Scala 2.11.0 via the [macro paradise plugin](http://docs.scala-lang.org/overviews/macros/annotations.html).
34
+
4)**[Type macros](typemacros.html) and [macro annotations](annotations.html)**. Neither type macros, not macro annotations are included of Scala 2.11.0. It is highly unlikely that type macros will ever be included in Scala, but we still deliberate on macro annotations. However, macro annotations are available both for Scala 2.10.x and for Scala 2.11.0 via the [macro paradise plugin](annotations.html).
35
35
36
36
5)**@compileTimeOnly**. Standard library now features a new `scala.annotations.compileTimeOnly` annotation that tells scalac that its annottees should not be referred to after type checking (which includes macro expansion). The main use case for this annotation is marking helper methods that are only supposed be used only together with an enclosing macro call to indicate parts of arguments of that macro call that need special treatment (e.g. `await` in scala/async or `value` in sbt's new macro-based DSL). For example, scala/async's `await` marked as `@compileTimeOnly` only makes sense inside an `async { ... }` block that compiles it away during its transformation, and using it outside of `async` is a compile-time error thanks to the new annotation.
37
37
38
38
### Changes to the macro engine
39
39
40
-
6)**[Blackbox/whitebox separation](http://docs.scala-lang.org/overviews/macros/blackbox-whitebox.html)**. Macros whose macro implementations use `scala.reflect.macros.blackbox.Context` (new in Scala 2.11.0) are called blackbox, have reduced power in comparison to macros in 2.10.x, better support in IDEs and better perspectives in becoming part of Scala. Macros whose macro implementations use `scala.reflect.macros.whitebox.Context` (new in Scala 2.11.0) or `scala.reflect.macros.Context` (the only context in Scala 2.10.x, deprecated in Scala 2.11.0) are called whitebox and have at least the same power as macros in 2.10.x.
40
+
6)**[Blackbox/whitebox separation](blackbox-whitebox.html)**. Macros whose macro implementations use `scala.reflect.macros.blackbox.Context` (new in Scala 2.11.0) are called blackbox, have reduced power in comparison to macros in 2.10.x, better support in IDEs and better perspectives in becoming part of Scala. Macros whose macro implementations use `scala.reflect.macros.whitebox.Context` (new in Scala 2.11.0) or `scala.reflect.macros.Context` (the only context in Scala 2.10.x, deprecated in Scala 2.11.0) are called whitebox and have at least the same power as macros in 2.10.x.
41
41
42
-
7) **[Macro bundles](http://docs.scala-lang.org/overviews/macros/bundles.html)**. It is well-known that path-dependent nature of the current reflection API (that's there in both Scala 2.10.x and Scala 2.11.0) makes it difficult to modularize macros. There are [design patterns](http://docs.scala-lang.org/overviews/macros/overview.html#writing_bigger_macros) that help to overcome this difficulty, but that just leads to proliferation of boilerplate. One of the approaches to dealing with this problem is doing away with cakes altogether, and that's what we're pursing in Project Palladium, but that was too big of a change to pull off in Scala 2.11.0, so we've come up with a workaround that would alleviate the problem until the real solution arrives. Macro bundles are classes that have a single public field of type `Context` and any public method inside a bundle can be referred to as a macro implementation. Such macro implementations can then easily call into other methods of the same class or its superclasses without having to carry the context around, because the bundle already carries the context that everyone inside it can see and refer to. This significantly simplifies writing and maintaining complex macros.
42
+
7) **[Macro bundles](bundles.html)**. It is well-known that path-dependent nature of the current reflection API (that's there in both Scala 2.10.x and Scala 2.11.0) makes it difficult to modularize macros. There are [design patterns](overview.html#writing-bigger-macros) that help to overcome this difficulty, but that just leads to proliferation of boilerplate. One of the approaches to dealing with this problem is doing away with cakes altogether, and that's what we're pursing in Project Palladium, but that was too big of a change to pull off in Scala 2.11.0, so we've come up with a workaround that would alleviate the problem until the real solution arrives. Macro bundles are classes that have a single public field of type `Context` and any public method inside a bundle can be referred to as a macro implementation. Such macro implementations can then easily call into other methods of the same class or its superclasses without having to carry the context around, because the bundle already carries the context that everyone inside it can see and refer to. This significantly simplifies writing and maintaining complex macros.
43
43
44
44
8)**Relaxed requirements for signatures of macro implementations**. With the advent of quasiquotes, reify is quickly growing out of favor as being too clunky and inflexible. To recognize that we now allow both arguments and return types of macro implementations to be of type `c.Tree` rather than `c.Expr[Something]`. There's no longer a need to write huge type signatures and then spend time and lines of code trying to align your macro implementations with those types. Just take trees in and return trees back - the boilerplate is gone.
45
45
@@ -120,11 +120,11 @@ Quasiquotes is the single most impressive upgrade for reflection and macros in S
120
120
121
121
### How to make your 2.11.0 macros work in 2.10.x
122
122
123
-
34)**Quasiquotes**. We don't plan to release quasiquotes as part of the Scala 2.10.x distribution, but they can still be used in Scala 2.10.x by the virtue of the macro paradise plugin. Read [paradise documentation](http://docs.scala-lang.org/overviews/macros/paradise.html) to learn more about what's required to use the compiler plugin, what are the binary compatibility consequences and what are the support guarantees.
123
+
34)**Quasiquotes**. We don't plan to release quasiquotes as part of the Scala 2.10.x distribution, but they can still be used in Scala 2.10.x by the virtue of the macro paradise plugin. Read [paradise documentation](paradise.html) to learn more about what's required to use the compiler plugin, what are the binary compatibility consequences and what are the support guarantees.
124
124
125
-
35)**Most of the new functionality doesn't have equivalents in 2.10.x**. We don't plan to backport any of the new functionality, e.g. fundep materialization or macro bundles, to Scala 2.10.x (except for maybe thread safety for runtime reflection). Consult [the roadmap of macro paradise for Scala 2.10.x](http://docs.scala-lang.org/overviews/macros/roadmap.html) to see what features are supported in paradise.
125
+
35)**Most of the new functionality doesn't have equivalents in 2.10.x**. We don't plan to backport any of the new functionality, e.g. fundep materialization or macro bundles, to Scala 2.10.x (except for maybe thread safety for runtime reflection). Consult [the roadmap of macro paradise for Scala 2.10.x](roadmap.html) to see what features are supported in paradise.
126
126
127
-
36)**Blackbox/whitebox**. If you're determined to have your macros blackbox, it's going to require additional effort to have those macros working consistently in both 2.10.x and 2.11.0, because in 2.10.x all macros are whitebox. First of all, make sure that you're not actually using any of [whitebox powers](http://docs.scala-lang.org/overviews/macros/blackbox-whitebox.html#codifying_the_distinction), otherwise you'll have to rewrite your macros first. Secondly, before returning from your macros impls, explicitly upcast the expansions to the type required by their macro defs. (Of course, none of this applies to whitebox macros. If don't mind your macros being whitebox, then you don't have to do anything to ensure cross-compatibility).
127
+
36)**Blackbox/whitebox**. If you're determined to have your macros blackbox, it's going to require additional effort to have those macros working consistently in both 2.10.x and 2.11.0, because in 2.10.x all macros are whitebox. First of all, make sure that you're not actually using any of [whitebox powers](blackbox-whitebox.html#codifying-the-distinction), otherwise you'll have to rewrite your macros first. Secondly, before returning from your macros impls, explicitly upcast the expansions to the type required by their macro defs. (Of course, none of this applies to whitebox macros. If don't mind your macros being whitebox, then you don't have to do anything to ensure cross-compatibility).
|[Type providers](/overviews/macros/typeproviders.html)| Partial support (see docs) | Yes <sup>2</sup> | Partial support (see docs) | Yes <sup>2</sup> | Partial support (see docs) | Yes <sup>2</sup> |
Copy file name to clipboardExpand all lines: _overviews/parallel-collections/overview.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,7 +82,7 @@ only. As a general heuristic, speed-ups tend to be noticeable when the size of
82
82
the collection is large, typically several thousand elements. (For more
83
83
information on the relationship between the size of a parallel collection and
84
84
performance, please see the
85
-
[appropriate subsection]({{ site.baseurl}}/overviews/parallel-collections/performance.html#how_big_should_a_collection_be_to_go_parallel) of the [performance]({{ site.baseurl }}/overviews/parallel-collections/performance.html)
85
+
[appropriate subsection]({{ site.baseurl}}/overviews/parallel-collections/performance.html#how-big-should-a-collection-be-to-go-parallel) of the [performance]({{ site.baseurl }}/overviews/parallel-collections/performance.html)
| Aug 8th 2017 | Numbered SIP, improve view, fixed example, and added related issues |
20
+
19
21
20
22
Your feedback is welcome! If you're interested in discussing this proposal, head over to [this](https://contributors.scala-lang.org/t/sip-nn-make-infix-type-alias-precedence-like-expression-operator-precedence/471) Scala Contributors thread and let me know what you think.
21
23
@@ -30,70 +32,70 @@ Infix types are 'mostly' left-associative,
30
32
while the expression operation precedence is determined by the operator's first character (e.g., `/` is precedent to `+`).
31
33
Please see [Infix Types](http://scala-lang.org/files/archive/spec/2.12/03-types.html#infix-types) and [Infix Operations](http://scala-lang.org/files/archive/spec/2.12/06-expressions.html#infix-operations) sections of the Scala specifications for more details.
//Left expands to Plus[Div[Plus[N1,N2],N3],N4] (Surprising)
61
+
//Right expands to Plus[Plus[N1,Div[N2,N3]],N4]
62
+
implicitly[(N1+N2/N3+N4) =:= (N1+ (N2/N3) +N4)]
63
+
}
64
+
```
63
65
64
66
### Prefix operators bracketless unary use
65
67
While expressions have prefix unary operators, there are none for types. See the [Prefix Operations](http://scala-lang.org/files/archive/spec/2.12/06-expressions.html#prefix-operations) section of the Scala specification.
66
68
This is a lacking feature of the type language Scala offers. See also interactions of this feature with other Scala features, further down this text.
67
69
68
70
69
-
**Example**:
70
-
71
-
{% highlight scala %}
72
-
object PrefixExpression {
73
-
case class Nummy(expand : String) {
74
-
def unary_- : Nummy = Nummy(s"-$this")
75
-
def unary_~ : Nummy = Nummy(s"~$this")
76
-
def unary_! : Nummy = Nummy(s"!$this")
77
-
def unary_+ : Nummy = Nummy(s"+$this")
78
-
}
79
-
object N extends Nummy("N")
80
-
val n1 = -N
81
-
val n2 = ~N
82
-
val n3 = !N
83
-
val n4 = +N
84
-
}
85
-
object NonExistingPrefixTypes {
86
-
trait unary_-[A]
87
-
trait unary_~[A]
88
-
trait unary_![A]
89
-
trait unary_+[A]
90
-
trait N
91
-
type N1 = -N //Not working
92
-
type N2 = ~N //Not working
93
-
type N3 = !N //Not working
94
-
type N4 = +N //Not working
95
-
}
96
-
{% endhighlight %}
71
+
**Prefix expression vs. prefix type example**:
72
+
73
+
```scala
74
+
objectPrefixExpression {
75
+
caseclassNummy(expand : String) {
76
+
defunary_-:Nummy=Nummy(s"-$this")
77
+
defunary_~:Nummy=Nummy(s"~$this")
78
+
defunary_!:Nummy=Nummy(s"!$this")
79
+
defunary_+:Nummy=Nummy(s"+$this")
80
+
}
81
+
objectNextendsNummy("N")
82
+
valn1=-N
83
+
valn2=~N
84
+
valn3=!N
85
+
valn4=+N
86
+
}
87
+
objectNonExistingPrefixTypes {
88
+
traitunary_-[A]
89
+
traitunary_~[A]
90
+
traitunary_![A]
91
+
traitunary_+[A]
92
+
traitN
93
+
typeN1=-N//Not working
94
+
typeN2=~N//Not working
95
+
typeN3=!N//Not working
96
+
typeN4=+N//Not working
97
+
}
98
+
```
97
99
98
100
---
99
101
@@ -124,30 +126,30 @@ Dotty has no prefix types, same as Scalac.
124
126
The [singleton-ops library](https://github.com/fthomas/singleton-ops) with [Typelevel Scala](https://github.com/typelevel/scala) (which implemented [SIP-23](http://docs.scala-lang.org/sips/pending/42.type.html)) enables developers to express literal type operations more intuitively.
[This](http://stackoverflow.com/questions/23333882/scala-infix-type-aliasing-for-2-type-parameters) stackoverflow question demonstrate developers are 'surprised' by the difference in infix precedence, expecting infix type precedence to act the same as expression operations.
@@ -160,40 +162,67 @@ We currently loose some of the intuitive appeal due to the precedence issue:
160
162
Variance annotation uses the `-` and `+` symbols to annotate contravariant and covariant subtyping, respectively. Introducing unary prefix types may lead to some developer confusion.
161
163
E.g.
162
164
163
-
{% highlight scala %}
164
-
trait Negate[A]
165
-
trait Positive[A]
166
-
type unary_-[A] = Negate[A]
167
-
type unary_+[A] = Positive[A]
168
-
trait Contravariant[B, -A <: -B] //contravariant A subtype upper-bounded by Negate[B]
169
-
trait Covariant[B, +A <: +B] //covariant A subtype upper-bounded by Positive[B]
170
-
{% endhighlight %}
165
+
```scala
166
+
traitNegate[A]
167
+
traitPositive[A]
168
+
typeunary_-[A] =Negate[A]
169
+
typeunary_+[A] =Positive[A]
170
+
traitContravariant[B, -A<:-B] //contravariant A subtype upper-bounded by Negate[B]
171
+
traitCovariant[B, +A<:+B] //covariant A subtype upper-bounded by Positive[B]
172
+
```
171
173
172
174
#### Negative Literal Types
173
175
Negative literal types are annotated using the `-` symbol. This can lead to the following confusion:
174
176
175
-
{% highlight scala %}
176
-
trait Negate[A]
177
-
type unary_-[A] = Negate[A]
178
-
trait MyTrait[B]
177
+
```scala
178
+
traitNegate[A]
179
+
typeunary_-[A] =Negate[A]
180
+
traitMyTrait[B]
179
181
180
-
type MinusFortyTwo = MyTrait[-42]
181
-
type NegateFortyTwo = MyTrait[Negate[42]]
182
-
{% endhighlight %}
182
+
typeMinusFortyTwo=MyTrait[-42]
183
+
typeNegateFortyTwo=MyTrait[Negate[42]]
184
+
```
183
185
184
186
The above example demonstrates a case of two types `MinusFortyTwo` and `NegateFortyTwo` which are different. They may be equivalent in view (implicit conversion between the two type instances), but they are not equal.
185
187
186
188
Note: It is not possible to annotate a positive literal type in Scala (checked both in TLS and Dotty):
187
189
188
-
{% highlight scala %}
189
-
val a : 42 = +42 //works
190
-
val b : -42 = -42 //works
191
-
val c : +42 = 42 //error: ';' expected but integer literal found
192
-
{% endhighlight %}
190
+
```scala
191
+
vala:42=+42//works
192
+
valb:-42=-42//works
193
+
valc:+42=42//error: ';' expected but integer literal found
194
+
```
193
195
194
196
This means that if unary prefix types are added, then `+42` will be a type expansion of `unary_+[42]`.
Both SIP23 implementation and Dotty's implementation of literal types currently fail compilation when infix types interact with a negative literal type.
203
+
```scala
204
+
type~~[A, B]
205
+
typegood=2~~2
206
+
typebad=2~~-2//Error:(9, 20) ';' expected but integer literal found.
207
+
typework_around=2~~ (-2) //works for Typelevel scala, but fails in Dotty
208
+
```
209
+
It is not yet clear if this is an implementation issue, or if the spec should be changed to allow this as well.
210
+
If this is a spec change, then the committee should approve it also.
211
+
212
+
#### Star `*` infix type interaction with repeated parameters
213
+
The [repeated argument symbol `*`](https://www.scala-lang.org/files/archive/spec/2.12/04-basic-declarations-and-definitions.html#repeated-parameters) may create confusion with the infix type `*`.
214
+
Please note that this feature interaction already exists within the current specification.
215
+
216
+
```scala
217
+
trait*[N1, N2]
218
+
traitN1
219
+
traitN2
220
+
deffoo(a : N1*N2*) :Unit= {} //repeated parameter of type *[N1, N2]
This document is intended to outline some basic Scala stylistic guidelines which should be followed with more or less fervency. Wherever possible, this guide attempts to detail why a particular style is encouraged and how it relates to other alternatives. As with all style guides, treat this document as a list of rules to be broken. There are certainly times when alternative styles should be preferred over the ones given here.
<li><a href="{{ site.baseurl }}/style/naming-conventions.html#higher-kinds-and-parameterized-type-parameters">Higher-Kinds and Parameterized Type parameters</a></li>
-[Classes, Objects, and Traits](scaladoc.html#classes-objects-and-traits)
68
+
-[Classes](scaladoc.html#classes)
69
+
-[Objects](scaladoc.html#objects)
70
+
-[Traits](scaladoc.html#traits)
71
+
-[Methods and Other Members](scaladoc.html#methods-and-other-members)
133
72
134
-
<divclass="span8">
73
+
### Thanks to ###
135
74
136
-
<h3>Thanks to</h3>
137
-
<p><ahref="http://www.codecommit.com/">Daniel Spiewak</a> and <ahref="http://www.naildrivin5.com/">David Copeland</a> for putting this style guide together, and Simon Ochsenreither for converting it to Markdown.</p>
138
-
139
-
</div>
75
+
[Daniel Spiewak](http://www.codecommit.com/) and [David Copeland](http://www.naildrivin5.com/) for putting this style guide together, and Simon Ochsenreither for converting it to Markdown.
Copy file name to clipboardExpand all lines: _tour/tour-of-scala.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,9 +19,9 @@ Scala is a modern multi-paradigm programming language designed to express common
19
19
Scala is a pure object-oriented language in the sense that [every value is an object](unified-types.html). Types and behavior of objects are described by [classes](classes.html) and [traits](traits.html). Classes are extended by subclassing and a flexible [mixin-based composition](mixin-class-composition.html) mechanism as a clean replacement for multiple inheritance.
20
20
21
21
## Scala is functional ##
22
-
Scala is also a functional language in the sense that [every function is a value](unified-types.html). Scala provides a [lightweight syntax](anonymous-function-syntax.html) for defining anonymous functions, it supports [higher-order functions](higher-order-functions.html), it allows functions to be [nested](nested-functions.html), and supports [currying](currying.html). Scala's [case classes](case-classes.html) and its built-in support for [pattern matching](pattern-matching.html) model algebraic types used in many functional programming languages. [Singleton objects](singleton-objects.html) provide a convenient way to group functions that aren't members of a class.
22
+
Scala is also a functional language in the sense that [every function is a value](unified-types.html). Scala provides a [lightweight syntax](basic.html#functions) for defining anonymous functions, it supports [higher-order functions](higher-order-functions.html), it allows functions to be [nested](nested-functions.html), and supports [currying](currying.html). Scala's [case classes](case-classes.html) and its built-in support for [pattern matching](pattern-matching.html) model algebraic types used in many functional programming languages. [Singleton objects](singleton-objects.html) provide a convenient way to group functions that aren't members of a class.
23
23
24
-
Furthermore, Scala's notion of pattern matching naturally extends to the [processing of XML data](xml-processing.html) with the help of [right-ignoring sequence patterns](regular-expression-patterns.html), by way of general extension via [extractor objects](extractor-objects.html). In this context, [for comprehensions](for-comprehensions.html) are useful for formulating queries. These features make Scala ideal for developing applications like web services.
24
+
Furthermore, Scala's notion of pattern matching naturally extends to the [processing of XML data](https://github.com/scala/scala-xml/wiki/XML-Processing) with the help of [right-ignoring sequence patterns](regular-expression-patterns.html), by way of general extension via [extractor objects](extractor-objects.html). In this context, [for comprehensions](for-comprehensions.html) are useful for formulating queries. These features make Scala ideal for developing applications like web services.
25
25
26
26
## Scala is statically typed ##
27
27
Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. In particular, the type system supports:
@@ -31,7 +31,7 @@ Scala is equipped with an expressive type system that enforces statically that a
31
31
*[upper](upper-type-bounds.html) and [lower](lower-type-bounds.html) type bounds,
32
32
*[inner classes](inner-classes.html) and [abstract types](abstract-types.html) as object members
*[implicit parameters](implicit-parameters.html) and [conversions](implicit-conversions.html)
36
36
*[polymorphic methods](polymorphic-methods.html)
37
37
@@ -43,6 +43,6 @@ In practice, the development of domain-specific applications often requires doma
43
43
44
44
A joint use of both features facilitates the definition of new statements without using meta-programming facilities such as macros.
45
45
46
-
Scala is designed to interoperate well with the popular Java 2 Runtime Environment (JRE). In particular, the interaction with the mainstream object-oriented Java programming language is as smooth as possible. Newer Java features like [annotations](annotations.html) and Java generics have direct analogues in Scala. Those Scala features without Java analogues, such as [default](default-parameter-values.html) and [named parameters](named-parameters.html), compile as close to Java as they can reasonably come. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and allows access to thousands of existing high-quality libraries.
46
+
Scala is designed to interoperate well with the popular Java 2 Runtime Environment (JRE). In particular, the interaction with the mainstream object-oriented Java programming language is as smooth as possible. Newer Java features like [annotations](annotations.html) and Java generics have direct analogues in Scala. Those Scala features without Java analogues, such as [default](default-parameter-values.html) and [named parameters](named-arguments.html), compile as close to Java as they can reasonably come. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and allows access to thousands of existing high-quality libraries.
Copy file name to clipboardExpand all lines: getting-started-intellij-track/building-a-scala-project-with-intellij-and-sbt.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ or more than one code file.
15
15
## Creating the project
16
16
In this section, we'll show you how to create the project in IntelliJ. However, if you're
17
17
comfortable with the command line, we recommend you try [Getting
18
-
Started with Scala and sbt on the Command Line]({{site.baseurl}}/documentation/getting-started-sbt-track/getting-started-with-scala-and-sbt-on-the-command-line.html) and then come back
18
+
Started with Scala and sbt on the Command Line]({{site.baseurl}}/getting-started-sbt-track/getting-started-with-scala-and-sbt-on-the-command-line.html) and then come back
19
19
here to the section "Writing Scala code".
20
20
21
21
1. If you didn't create the project from the command line, open up IntelliJ and select "Create New Project"
@@ -86,7 +86,7 @@ extra functionality to our apps.
Copy file name to clipboardExpand all lines: getting-started.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,9 +53,9 @@ Scala project. -->
53
53
## Next Steps
54
54
Once you've finished these tutorials, check out
55
55
56
-
*[The Tour of Scala](http://docs.scala-lang.org/tutorials/tour/tour-of-scala.html) for bite-sized introductions to Scala's features.
57
-
*[Learning Resources](learn), which includes online interactive tutorials and courses.
58
-
*[Our list of some popular Scala books]({{ site.baseurl }}/books.html).
56
+
*[The Tour of Scala](tutorials/tour/tour-of-scala.html) for bite-sized introductions to Scala's features.
57
+
*[Learning Resources](learn.html), which includes online interactive tutorials and courses.
58
+
*[Our list of some popular Scala books](books.html).
59
59
60
60
## Getting Help
61
61
There are a multitude of mailing lists and real-time chat channels in case you want to quickly connect with other Scala users. Check out our [community](https://scala-lang.org/community/) page a list of these resources and where to reach out for help.
0 commit comments