I have a bunch of code that uses a Map[String, Float]. So I'd like to do
type DocumentVector = Map[String, Float]
...
var vec = new DocumentVector
but this does not compile. I get the message:
trait Map is abstract; cannot be instantiated
[error] var vec = new DocumentVector
Ok, I think I understand what is going on here. Map is not a concrete class, it just produces an object via (). So I could do:
object DocumentVector { def apply() = { Map[String, Float]() } }
...
var vec = DocumentVector()
That works, though it's a bit clunky. But now I want to nest the types. I'd like to write:
type DocumentVector = Map[String, Float]
type DocumentSetVectors = Map[DocumentID, DocumentVector]
but this gives same "cannot be instantiated" problem. So I could try:
object DocumentVector { def apply() = { Map[String, Float]() } }
object DocumentSetVectors { def apply() = { Map[DocumentID, DocumentVector]() } }
but DocumentVector isn't actually a type, just an object with an apply() method, so the second line won't compile.
I feel like I'm missing something basic here...