Skip to content

Commit

Permalink
Merge pull request #466 from SethTisue/views-usually-means-collection…
Browse files Browse the repository at this point in the history
…s-these-days

Scala Tour: call them "implicit conversions" not "views"
  • Loading branch information
heathermiller committed Dec 8, 2015
2 parents 6d7efb5 + 6f84bab commit d076f98
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 110 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ _site
.DS_Store
.project
.settings
/.jekyll-metadata
*~
vendor/bundle
.idea/
12 changes: 12 additions & 0 deletions es/tutorials/tour/implicit-conversions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
layout: tutorial
title: Implicit Conversions

disqus: true

tutorial: scala-tour
num: 32
language: es
---

(this page has not been translated into Spanish)
2 changes: 1 addition & 1 deletion es/tutorials/tour/tour-of-scala.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Scala cuenta con un expresivo sistema de tipado que fuerza estáticamente las ab
* [clases internas](inner-classes.html) y [tipos abstractos](abstract-types.html) como miembros de objetos,
* [tipos compuestos](compound-types.html)
* [auto-referencias explicitamente tipadas](explicitly-typed-self-references.html)
* [vistas](views.html)
* [implicit conversions](implicit-conversions.html)
* [métodos polimórficos](polymorphic-methods.html)

El [mecanismo de inferencia de tipos locales](local-type-inference.html) se encarga de que el usuario no tengan que anotar el programa con información redundante de tipado. Combinadas, estas características proveen una base poderosa para el reuso seguro de abstracciones de programación y para la extensión segura (en cuanto a tipos) de software.
Expand Down
51 changes: 0 additions & 51 deletions es/tutorials/tour/views.md

This file was deleted.

43 changes: 43 additions & 0 deletions tutorials/tour/implicit-conversions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
layout: tutorial
title: Implicit Conversions

disqus: true

tutorial: scala-tour
num: 26
tutorial-next: polymorphic-methods
tutorial-previous: implicit-parameters
---

An implicit conversion from type `S` to type `T` is defined by an implicit value which has function type `S => T`, or by an implicit method convertible to a value of that type.

Implicit conversions are applied in two situations:

* If an expression `e` is of type `S`, and `S` does not conform to the expression's expected type `T`.
* In a selection `e.m` with `e` of type `T`, if the selector `m` does not denote a member of `T`.

In the first case, a conversion `c` is searched for which is applicable to `e` and whose result type conforms to `T`.
In the second case, a conversion `c` is searched for which is applicable to `e` and whose result contains a member named `m`.

The following operation on the two lists xs and ys of type `List[Int]` is legal:

xs <= ys

assuming the implicit methods `list2ordered` and `int2ordered` defined below are in scope:

implicit def list2ordered[A](x: List[A])
(implicit elem2ordered: A => Ordered[A]): Ordered[List[A]] =
new Ordered[List[A]] { /* .. */ }

implicit def int2ordered(x: Int): Ordered[Int] =
new Ordered[Int] { /* .. */ }

The implicitly imported object `scala.Predef` declares several predefined types (e.g. `Pair`) and methods (e.g. `assert`) but also several implicit conversions.

For example, when calling a Java method that expects a `java.lang.Integer`, you are free to pass it a `scala.Int` instead. That's because Predef includes the following implicit conversions:

implicit def int2Integer(x: Int) =
java.lang.Integer.valueOf(x)

To define your own implicit conversions, you must first `import scala.language.implicitConversions` (or invoke the compiler with `-language:implicitConversions`). The feature must be explicitly enabled because it has pitfalls if used indiscriminately.
2 changes: 1 addition & 1 deletion tutorials/tour/implicit-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ disqus: true

tutorial: scala-tour
num: 25
tutorial-next: views
tutorial-next: implicit-conversions
tutorial-previous: explicitly-typed-self-references
---

Expand Down
2 changes: 1 addition & 1 deletion tutorials/tour/polymorphic-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tutorial: scala-tour
num: 27

tutorial-next: local-type-inference
tutorial-previous: views
tutorial-previous: implicit-conversions
---

Methods in Scala can be parameterized with both values and types. Like on the class level, value parameters are enclosed in a pair of parentheses, while type parameters are declared within a pair of brackets.
Expand Down
2 changes: 1 addition & 1 deletion tutorials/tour/tour-of-scala.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Scala is equipped with an expressive type system that enforces statically that a
* [inner classes](inner-classes.html) and [abstract types](abstract-types.html) as object members
* [compound types](compound-types.html)
* [explicitly typed self references](explicitly-typed-self-references.html)
* [implicit parameters](implicit-parameters.html) and [views](views.html)
* [implicit parameters](implicit-parameters.html) and [conversions](implicit-conversions.html)
* [polymorphic methods](polymorphic-methods.html)

A [local type inference mechanism](local-type-inference.html) takes care that the user is not required to annotate the program with redundant type information. In combination, these features provide a powerful basis for the safe reuse of programming abstractions and for the type-safe extension of software.
Expand Down
2 changes: 1 addition & 1 deletion tutorials/tour/unified-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ In contrast to Java, all values in Scala are objects (including numerical values
## Scala Class Hierarchy ##

The superclass of all classes `scala.Any` has two direct subclasses `scala.AnyVal` and `scala.AnyRef` representing two different class worlds: value classes and reference classes. All value classes are predefined; they correspond to the primitive types of Java-like languages. All other classes define reference types. User-defined classes define reference types by default; i.e. they always (indirectly) subclass `scala.AnyRef`. Every user-defined class in Scala implicitly extends the trait `scala.ScalaObject`. Classes from the infrastructure on which Scala is running (e.g. the Java runtime environment) do not extend `scala.ScalaObject`. If Scala is used in the context of a Java runtime environment, then `scala.AnyRef` corresponds to `java.lang.Object`.
Please note that the diagram above also shows implicit conversions called views between the value classs.
Please note that the diagram above also shows implicit conversions between the value classes.
Here is an example that demonstrates that both numbers, characters, boolean values, and functions are objects just like every other object:

object UnifiedTypes extends App {
Expand Down
54 changes: 0 additions & 54 deletions tutorials/tour/views.md

This file was deleted.

0 comments on commit d076f98

Please sign in to comment.