Changing that to:
def list2Tree2[T <% Ordered[T]](list: List[T]) = (list foldRight
(Empty: Tree[T])) { insert(_, _) }
or maybe
def list2Tree2[T <% Ordered[T]](list: List[T]): Tree[T] = (list
foldRight Empty) { insert(_, _) }
should work. The reason why you get that error is somewhere in my
head, but I just can't seem to find it... oh well. I'm pretty sure one
of these 2 changes should fix it. I'm pretty sure the same thing
happens if you try to fold into a List and give it a Nil.
--
Derek
It infers from left to right and doesn't go back across parameter list
boundaries to change its mind. And it picks the most specific type.
You can use this to your advantage sometimes. Other times, like
foldLeft, it uses you instead. A simple illustration.
scala> def f1[T](x: T)(xs: Set[T]) = xs + x
f1: [T](x: T)(xs: Set[T])scala.collection.immutable.Set[T]
scala> f1("a")(Set(new AnyRef))
<console>:7: error: type mismatch;
found : java.lang.Object
required: java.lang.String
f1("a")(Set(new AnyRef))
^
scala> def f2[T](x: T, xs: Set[T]) = xs + x
f2: [T](x: T,xs: Set[T])scala.collection.immutable.Set[T]
scala> f2("a", Set(new AnyRef))
res1: scala.collection.immutable.Set[java.lang.Object] = Set(java.lang.Object@26bb2f6e, a)
--
Paul Phillips | Eschew mastication.
Caged Spirit |
Empiricist |
up hill, pi pals! |----------* http://www.improving.org/paulp/ *----------