diff options
author | Martin Odersky <odersky@gmail.com> | 2005-05-11 13:26:06 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2005-05-11 13:26:06 +0000 |
commit | 88a54be387762d1fdf96a8a128c84e95e613873c (patch) | |
tree | bfa66bd637aa0d44e40631403a4b879ccb6e98d4 /doc/reference | |
parent | cb6e13ecc4c8f011709d971519ac8aec57b7497a (diff) | |
download | scala-88a54be387762d1fdf96a8a128c84e95e613873c.tar.gz scala-88a54be387762d1fdf96a8a128c84e95e613873c.tar.bz2 scala-88a54be387762d1fdf96a8a128c84e95e613873c.zip |
*** empty log message ***
Diffstat (limited to 'doc/reference')
-rw-r--r-- | doc/reference/ExamplesPart.tex | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/doc/reference/ExamplesPart.tex b/doc/reference/ExamplesPart.tex index f6bcd5d595..8315cf519a 100644 --- a/doc/reference/ExamplesPart.tex +++ b/doc/reference/ExamplesPart.tex @@ -3359,8 +3359,9 @@ That is, \end{lstlisting} For associative and commutative operators, \code{/:} and \code{:\\} are equivalent (even though there may be a difference -in efficiency). But sometimes, only one of the two operators is -appropriate or has the right type: +in efficiency). +%But sometimes, only one of the two operators is +%appropriate or has the right type: \begin{exercise} Consider the problem of writing a function \code{flatten}, which takes a list of element lists as arguments. The result of @@ -3369,10 +3370,11 @@ single list. Here is the an implementation of this method in terms of \code{:\\}. \begin{lstlisting} def flatten[a](xs: List[List[a]]): List[a] = - (xs :\ Nil) {(x, xs) => x ::: xs} + (xs :\ (Nil: List[a])) {(x, xs) => x ::: xs} \end{lstlisting} -In this case it is not possible to replace the application of -\code{:\\} with \code{/:}. Explain why. +Consider replacing the first part of the body of \lstinline@flatten@ +by \lstinline@(Nil /: xs)@. What would be the difference in asymptotoc +complexity between the two versions of \lstinline@flatten@? In fact \code{flatten} is predefined together with a set of other userful function in an object called \code{List} in the standatd Scala |