Weird nested structural type in generics

一笑奈何 提交于 2019-12-04 12:12:24

The signature of the Functor type constructor shows that it is parameterised with another, unary, type constructor F:

trait Functor[F[_]] extends InvariantFunctor[F]

Neither R => A nor Function1[R,A] are type constructors; they take no parameters.

However in:

type λ[α] = (R) => α

λ is a type constructor taking one parameter, α. (R is already defined in this context.)

The syntax ({type λ[α]=(R) => α})#λ is known as a type lambda. It is a syntactic trick allowing a type alias to be created inline and referred to via a projection, so the whole expression can be used where a type is required.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!