Dotty first class polymorphic functions

May 06, 2020 18:09

https://github.com/lampepfl/dotty/blob/master/tests/run/polymorphic-functions.scala

type F0 = [T] => List[T] => Option[T] type F1 = [F[_], G[_], T] => (F[T], F[T] => G[T]) => G[T] type F11 = [F[_[_]], G[_[_]], T[_]] => (F[T], [U[_]] => F[U] => G[U]) => G[T] type F2 = [T, U] => (T, U) => Either[T, U] val t0 = [T] => (ts: List[T]) => ts.headOption val t0a: F0 = t0 assert(t0(List(1, 2, 3)) == Some(1)) val t1 = [F[_], G[_], T] => (ft: F[T], f: F[T] => G[T]) => f(ft) val t1a: F1 = t1 assert(t1(List(1, 2, 3), (ts: List[Int]) => ts.headOption) == Some(1)) val t11 = [F[_[_]], G[_[_]], T[_]] => (fl: F[T], f: [U[_]] => F[U] => G[U]) => f(fl) val t11a: F11 = t11 case class C11[F[_]](is: F[Int]) case class D11[F[_]](is: F[Int]) assert(t11[F = C11](C11(List(1, 2, 3)), [U[_]] => (c: C11[U]) => D11(c.is)) == D11(List(1, 2, 3)))

dotty

Previous post Next post
Up