Skip to content

Instantly share code, notes, and snippets.

@fedesilva
Forked from retronym/type-bounds.scala
Created September 14, 2010 23:04
Show Gist options
  • Select an option

  • Save fedesilva/579931 to your computer and use it in GitHub Desktop.

Select an option

Save fedesilva/579931 to your computer and use it in GitHub Desktop.
//
// Upper Type Bound
//
def upperTypeBound[AA <: A](x: AA): A = x
// equivalently, require a implicit parameter of <:<[AA, A].
// This method must be used if A is an abstract type from the
// enclosing scope.
def upperTypeBound2[AA](x: AA)(implicit ev: AA <:< A): A = x // compiles to ev(x)
//
// View Bound
//
def viewBound[AA <% A](x: AA): A = x
//compiles to:
def viewBound$[AA](x: AA)(implicit ev1$: AA => A) = ev1$(x)
//
// Context Bound
//
def contextBound[X: B](x: X)
//compiles to:
def contextBound$[X](x: X)(implicit ev1$: B[X])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment