diff options
author | schinz <schinz@epfl.ch> | 2004-04-14 13:21:05 +0000 |
---|---|---|
committer | schinz <schinz@epfl.ch> | 2004-04-14 13:21:05 +0000 |
commit | fbd9b93cc4f10e90da94d963f3e052803e93acfd (patch) | |
tree | 7cbbecaafee074b726d2ac435764e845e06e120b /doc | |
parent | 483f42e9ab225b4f3d0e2aee412e5b1a91fbb97b (diff) | |
download | scala-fbd9b93cc4f10e90da94d963f3e052803e93acfd.tar.gz scala-fbd9b93cc4f10e90da94d963f3e052803e93acfd.tar.bz2 scala-fbd9b93cc4f10e90da94d963f3e052803e93acfd.zip |
- corrected examples for variance annotations,
- changed a few occurrences of the old "multiple val" syntax to the
new one (i.e. replaced "val x = 1, y = 2;" by "val x = 1; val y = 2;")
Diffstat (limited to 'doc')
-rw-r--r-- | doc/reference/ReferencePart.tex | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/doc/reference/ReferencePart.tex b/doc/reference/ReferencePart.tex index f0bb1842a7..13f3f90c82 100644 --- a/doc/reference/ReferencePart.tex +++ b/doc/reference/ReferencePart.tex @@ -1270,22 +1270,23 @@ the variance position of the enclosing type ~\lstinline@$S$[$\ldots T \ldots$ ]@ \example The following variance annotation is legal. \begin{lstlisting} -class P[a, b] { - val fst: a, snd: b -}\end{lstlisting} +abstract class P[+a, +b] { + def fst: a; def snd: b +} +\end{lstlisting} With this variance annotation, elements of type $P$ subtype covariantly with respect to their arguments. For instance, \begin{lstlisting} -P[IOExeption, String] <: P[Throwable, AnyRef] . +P[IOException, String] <: P[Throwable, AnyRef] . \end{lstlisting} If we make the elements of $P$ mutable, the variance annotation becomes illegal. \begin{lstlisting} -class Q[+a, +b] { - var fst: a, snd: b // **** error: illegal variance: - // `a', `b' occur in invariant position. +abstract class Q[+a, +b] { + var fst: a; // **** error: illegal variance: + var snd: b // `a', `b' occur in invariant position. } \end{lstlisting} @@ -2312,7 +2313,7 @@ abstract class Point { def isOrigin = (x == 0.0 && y == 0.0); } object Point { - val origin = new Point() { val x = 0.0, y = 0.0 } + val origin = new Point() { val x = 0.0; val y = 0.0 } } \end{lstlisting} This defines a class \code{Point} and an object \code{Point} which @@ -2719,7 +2720,8 @@ alternatives in $\BB$. class A extends B {} def f(x: B, y: B) = $\ldots$ def f(x: A, y: B) = $\ldots$ - val a: A, b: B + val a: A; + val b: B \end{lstlisting} Then the application \lstinline@f(b, b)@ refers to the first definition of $f$ whereas the application \lstinline@f(a, a)@ |