7

Possible Duplicate:
What do <:<, <%<, and =:= mean in Scala 2.8, and where are they documented?

e.g. in this example, from scala-arm 1.0:

def toTraversable[B](implicit ev: R <:< TraversableOnce[B]): Traversable[B] = 
  new ManagedTraversable[B,R] {
    val resource = self
    override protected def internalForeach[U](resource: R, g : B => U) : Unit = 
      ev(resource).foreach(g) 
  }
2

1 Answer 1

7

<:< (and similar strange looking constructs) are defined in Predef.scala (source at scala-lang.org), which is probably the best resource for working out what they are.

In general, classes like that can be used to provide further bounds on the type parameters within the scope of a particular method.

The <:< in particular is used to require that R is a subtype of TraversableOnce[B].

The description from documentation is:

An instance of A <:< B witnesses that A is a subtype of B. Requiring an implicit argument of the type A <:< B encodes the generalized constraint A <: B.

To constrain any abstract type T that's in scope in a method's argument list (not just the method's own type parameters) simply add an implicit argument of type T <:< U, where U is the required upper bound; or for lower-bounds, use: L <:< T, where L is the required lower bound.

Not the answer you're looking for? Browse other questions tagged or ask your own question.