加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – “应该启用更高的键控类型”警告

发布时间:2020-12-16 18:53:29 所属栏目:安全 来源:网络整理
导读:在以下代码中(从 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]} 我
在以下代码中(从 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.

…虽然它经常会在崩溃的早期终止.

那只是个玩笑.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读