Reputation: 67290
I am having trouble with scalac not finding a manifest for a higher-kinded internal type I want to use. Consider some list like type with a constructor:
trait L[S, A]
def emptyList[S, A: Manifest]: L[S, A] = ???
Now another type which gets constructed from its companion object like this:
object Tree {
private class Leaf[S, A]
private class Impl[S, A](l: L[S, Leaf[S, A]]) extends Tree[S, A]
def empty[S, A]: Tree[S, A] = new Impl(emptyList[S, Leaf[S, A]])
}
trait Tree[S, A]
It fails because scalac wants a manifest for type Leaf[S, A]
. Why isn't that available? I don't want to relax visibility of Leaf
and clutter the constructor by asking to pass in a manifest argument.
I don't understand this at all—I thought that from the JVM perspective, the arrays that are constructed in L
boil down to Array[Leaf[_, _]]
aka Array[java.lang.Object]
, so what's the point of this refusal?
Any ways to find the manifest?
Upvotes: 3
Views: 272
Reputation: 1184
You have to provide manifest for all your parameters, in effect creating a complete manifest chain:
def emptyList[ S, A : Manifest ] {}
class Leaf[ S, A ]
def emptyTree[ S: Manifest, A : Manifest ] { emptyList[ S, Leaf[ S, A ]]}
Upvotes: 4