sealed abstract class <:<[-From, +To] extends From => To, Serializable
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.
In case of any confusion over which method goes in what direction, all the "Co" methods (including apply) go from left to right in the type ("with" the type), and all the "Contra" methods go from right to left ("against" the type). E.g., apply turns a From into a To, and substituteContra replaces the Tos in a type with Froms.
sealed trait Option[+A] {
// def flatten[B, A <: Option[B]]: Option[B] = ...
// won't work, since the A in flatten shadows the class-scoped A.
def flatten[B](implicit ev: A <:< Option[B]): Option[B]
= if(isEmpty) None else ev(get)
// Because (A <:< Option[B]) <: (A => Option[B]), ev can be called to turn the
// A from get into an Option[B], and because ev is implicit, that call can be
// left out and inserted automatically.
}
Substitute To for From and From for To in the type F[To, From], given that F is contravariant in the first argument and covariant in the second.
Substitute To for From and From for To in the type F[To, From], given that F is contravariant in the first argument and covariant in the second. Essentially swaps To and From in ftf's type.
This method is impossible to implement without throwing or otherwise "cheating" unless From <: To, so it ensures that this really represents a subtyping relationship.
This method is impossible to implement without throwing or otherwise "cheating" unless From <: To, so it ensures that this really represents a subtyping relationship.
This method is impossible to implement without throwing or otherwise "cheating" unless From <: To, so it ensures that this really represents a subtyping relationship.