Frage

Possible Duplicate:
Context bounds shortcut with higher kinded-types

Why doesn't the Scala compiler let me write this?

class TypeCtor[M[_]: ClassManifest]

It complains with “error: type M takes type parameters”. If I'm only asking for the ClassManifest, the compiler should be able to insert it no matter what the parametrization of M is, no?

This works as expected:

class TypeCtor[M[_]](implicit val ev: ClassManifest[M[_]])
(new TypeCtor[Vector]).ev.erasure // => class scala.collection.immutable.Vector
War es hilfreich?

Lösung

See my answer to this question.

Andere Tipps

The parameterization of M is indeeed irrelevant, but the Scala compiler needs a parameter for ClassManifest in order to know which manifest to insert. Let's say we have

class TypeCtor[A,B](implicit val ev: ClassManifest)

Now the Compiler would not know whether to insert the Manifest of A or B. Also you can't write ClassManifest[M] because ClassManifest expects a Type of kind * and M has kind * -> *.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top