How to implement collection with covariance when delegating to another collection for storage?

Posted by memelet on Stack Overflow See other posts from Stack Overflow or by memelet
Published on 2010-05-21T18:34:59Z Indexed on 2010/05/21 20:00 UTC
Read the original article Hit count: 123

Filed under:
|

I'm trying to implement a type of SortedMap with extended semantics. I'm trying to delegate to SortedMap as the storage but can't get around the variance constraints:

class IntervalMap[A, +B](implicit val ordering: Ordering[A])
    //extends ...
{
  var underlying = SortedMap.empty[A, List[B]]
}

Here is the error I get. I understand why I get the error (I understand variance). What I don't get is how to implement this type of delegation. And yes, the covariance on B is required.

error: covariant type B occurs in contravariant position in type scala.collection.immutable.SortedMap[A,List[B]] of parameter of setter underlying_=

© Stack Overflow or respective owner

Related posts about scala-2.8

Related posts about scala