Guest User

Untitled

a guest
Jan 22nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. // Type Constraints --------------------------------------------------------------
  2.  
  3. /** An instance of `A <:< B` witnesses that `A` is a subtype of `B`.
  4. *
  5. * Requiring an implicit argument of the type `A <:< B` encodes the generalized constraint `A <: B`.
  6. *
  7. * @note we need a new type constructor `<:<` and evidence `conforms`, as
  8. * reusing `Function2` and `identity` leads to ambiguities in case of type errors (any2stringadd is inferred)
  9. * to constrain any abstract type T that's in scope in a method's argument list (not just the method's own type parameters)
  10. * simply add an implicit argument of type `T <:< U`, where U is the required upper bound (for lower-bounds, use: `L <:< T`,
  11. * where L is the required lower bound).
  12. * in part contributed by Jason Zaugg
  13. */
  14. @implicitNotFound(msg = "Cannot prove that ${From} <:< ${To}.")
  15. sealed abstract class <:<[-From, +To] extends (From => To) with Serializable
  16. implicit def conforms[A]: A <:< A = new (A <:< A) { def apply(x: A) = x }
  17. // not in the <:< companion object because it is also intended to subsume identity (which is no longer implicit)
  18.  
  19. /** An instance of `A =:= B` witnesses that the types `A` and `B` are equal.
  20. *
  21. * @see <:< for expressing subtyping constraints
  22. */
  23. @implicitNotFound(msg = "Cannot prove that ${From} =:= ${To}.")
  24. sealed abstract class =:=[From, To] extends (From => To) with Serializable
  25. object =:= {
  26. implicit def tpEquals[A]: A =:= A = new (A =:= A) {def apply(x: A) = x}
  27. }
Add Comment
Please, Sign In to add comment