scala - "Higher Kinded Type Should be Enabled"警告

标签 scala

在以下代码中(来自Functional Programming in Scala):

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]
}

我看到以下警告:
[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[_]] {

这里发生了什么?请注意,我阅读了此post,但听不懂。

最佳答案

请参阅higherKinds的文档。

Only where this flag is enabled, higher-kinded types can be written.

The level of abstraction implied by these design patterns is often a barrier to understanding for newcomers to a Scala codebase.



由于某些原因,没有人开玩笑:

Higher kinded types in Scala lead to a Turing-complete type system, where compiler termination is no longer guaranteed.



...尽管通常它会因崩溃而提前终止。

那只是个玩笑。

关于scala - "Higher Kinded Type Should be Enabled"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21642271/

相关文章:

generics - Scala 中的有界泛型(如 Java 中的 <E extends MyClass> )

scala - 如何配置 Ant 以运行(而不仅仅是编译)Scala?

eclipse - Scala IDE 可以建议自动导入包吗?

scala - 使用上下文边界 "negatively"确保类型类实例不存在于范围内

scala - PlayFramework FakeRequest 返回 400 错误

scala - 如何在 Scala 中抑制 "match is not exhaustive!"警告

特定测试前后的 Scalatest 运行代码

scala - 为什么方法参数 F 可以与类型构造函数 F 同名?

scala - += 操作在 Scala 映射中到底做了什么?

scala - Scala排序是否稳定?