在以下代码中(来自Scala中的Functional Programming):
trait Functor[F[_]] {
def map[A,B](fa: F[A])(f: A => B): F[B]
}
trait Monad[F[_]] {
def unit[A](a: => A): F[A]
def flatMap[A,B](ma: F[A])(f: A => F[B]): F[B]
def apply[A](a: => A): F[A]
}
Run Code Online (Sandbox Code Playgroud)
我看到以下警告:
[warn] C:\...\Monad.scala:3: higher-kinded type should be enabled
[warn] by making the implicit value scala.language.higherKinds visible.
[warn] This can be achieved by adding the import clause 'import scala.language.higherKinds'
[warn] or by setting the compiler option -language:higherKinds.
[warn] See the Scala docs for value scala.language.higherKinds for a discussion
[warn] why the feature should be explicitly enabled.
[warn] trait Functor[F[_]] {
[warn] ^
[warn] C:\...\Monad.scala:7: higher-kinded type should be enabled
[warn] by making the implicit value scala.language.higherKinds visible.
[warn] trait Monad[F[_]] {
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?请注意,我读过这篇文章,但不明白.
请参阅doc for higherKinds.
只有在启用此标志的位置,才能写入更高级的类型.
这些设计模式隐含的抽象级别通常是理解Scala代码库新手的障碍.
出于某种原因,没有人开玩笑说:
Scala中较高的kinded类型导致Turing-complete类型系统,不再保证编译器终止.
...虽然它经常会在崩溃的早期终止.
那只是个玩笑.