“应启用更高级的类型"警告 [英] "Higher Kinded Type Should be Enabled" Warning
问题描述
在以下代码中(来自 Scala 中的函数式编程):
In the following code (from 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[_]] {
这是怎么回事?请注意,我阅读了这篇帖子,但不明白.
What's going on here? Note that I read this post, but didn't understand it.
推荐答案
请参阅 higherKinds.
只有在启用此标志的情况下,才能写入更高级的类型.
Only where this flag is enabled, higher-kinded types can be written.
这些设计模式所隐含的抽象级别通常是Scala 代码库新手理解的障碍.
The level of abstraction implied by these design patterns is often a barrier to understanding for newcomers to a Scala codebase.
出于某种原因,没有人开玩笑:
For some reason, no one has joked about:
Scala 中更高级的类型导致了图灵完备的类型系统,不再保证编译器终止.
Higher kinded types in Scala lead to a Turing-complete type system, where compiler termination is no longer guaranteed.
...虽然它通常会因崩溃而提前终止.
...though often it will just terminate early with a crash.
这只是个玩笑.
这篇关于“应启用更高级的类型"警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!