Mark Lewis
Dec 15, 2021

--

Note that in Scala 3 you can define lambdas/anonymous functions with type parameters. See https://medium.com/scala-3/scala-3-type-lambdas-polymorphic-function-types-and-dependent-function-types-2a6eabef896d and https://dotty.epfl.ch/docs/reference/new-types/polymorphic-function-types.html

For example:

scala> val pfunc = [A] => (a1: A, a2: A) => List(a1, a2)

val pfunc: [A] => (A, A) => List[A] = <function2>

scala> pfunc(3, 6)

val res0: List[Int] = List(3, 6)

scala> pfunc("hi", "there")

val res1: List[String] = List(hi, there)

--

--

Mark Lewis
Mark Lewis

Written by Mark Lewis

Computer Science Professor, Planetary Rings Simulator, Scala Zealot

No responses yet