Aladdin - Scala Bugtracking
[#420] project: documentation priority: low category: bug
submitter assigned to status date submitted
Philippe Martin fixed 2005-04-13 16:41:10.0
subject Problem with the flatten exercise in ScalaByExample
code
what happened
In the "Scala by Example" document, the exercise 9.4.2 states that flatten may not be implemented w\
ith /:. That's wrong. Here is an implementation that uses /:. It's true that it is qua\
dratic in time, but it returns always the same result as the imlementation that uses :\.

def flatten[a](xs: List[List[a]]): List[a] =
  ((Nil: List[a]) /: xs) {(xs, x) => xs ::: x}

Furthermore, the given implementation for flatten does not compile. The value Nil n\ eeds to be annotated with the type Type[a].

what expected
[back to overview]
Changes of this bug report
Martin  edited on  2006-10-30 18:07:57.0