Implicit values are written using withFlags(Flags.IMPLICIT)
:
(DEF("intToRational") withFlags(Flags.IMPLICIT)
withParams(PARAM("x", IntClass)) := NEW("Rational", REF("x")))
This print as:
implicit def intToRational(x: Int) = new Rational(x)
Implicit parameters are also written using withFlags(Flags.IMPLICIT)
:
(DEF("greet")
withParams(PARAM("name", StringClass))
withParams(PARAM("config", "Config")
withFlags(Flags.IMPLICIT)) := BLOCK(
Predef_println APPLY(REF("config") APPLY REF("name"))
))
This prints as:
def greet(name: String)(implicit config: Config) {
println(config(name))
}
View bounds are written by calling VIEWBOUNDS(typ|"T")
on TYPEVAR(...)
:
(DEF("maxList", "T")
withTypeParams(TYPEVAR("T") VIEWBOUNDS TYPE_ORDERED("T"))
withParams(PARAM("elements", TYPE_LIST("T"))): Tree)
This prints as:
def maxList[T <% Ordered[T]](elements: List[T]): T
Context bounds are written by calling CONTEXTBOUNDS(typ|"T")
on TYPEVAR(...)
:
(DEF("put", UnitClass)
withTypeParams(TYPEVAR(sym.A) CONTEXTBOUNDS FullManifestClass)
withParams(PARAM("x", sym.A)): Tree)
This prints as:
def put[A : Manifest](x: A): Unit