PLDB
Languages Features Calendar CSV Lists Blog About Sponsor Add Language
GitHub icon

Implicit Arguments

Implicit Arguments

Implicit Arguments are a feature.

Arguments that are not passed by the function caller, but are found in the function caller's scope.


Languages with Implicit Arguments include Scala

Example from Scala:
// https://docs.scala-lang.org/tour/implicit-parameters.html abstract class Monoid[A] { def add(x: A, y: A): A def unit: A } object ImplicitTest { implicit val stringMonoid: Monoid[String] = new Monoid[String] { def add(x: String, y: String): String = x concat y def unit: String = "" } implicit val intMonoid: Monoid[Int] = new Monoid[Int] { def add(x: Int, y: Int): Int = x + y def unit: Int = 0 } def sum[A](xs: List[A])(implicit m: Monoid[A]): A = if (xs.isEmpty) m.unit else m.add(xs.head, sum(xs.tail)) def main(args: Array[String]): Unit = { println(sum(List(1, 2, 3))) // uses intMonoid implicitly println(sum(List("a", "b", "c"))) // uses stringMonoid implicitly } }
file-imports-feature.html 路 implicit-arguments-feature.html 路 implicit-type-casting-feature.html

View source

PLDB - Build the next great programming language 路 v2022 Day 28 Docs Build Acknowledgements Traffic Today Traffic Trends Mirrors GitHub feedback@pldb.com