Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Higher Kinded Type Should be Enabled" Warning

Tags:

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

I see the following warning:

[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.

like image 469
Kevin Meredith Avatar asked Feb 08 '14 05:02

Kevin Meredith


2 Answers

See the doc for 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.

For some reason, no one has joked about:

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.

That's just a joke.

like image 91
som-snytt Avatar answered Sep 22 '22 03:09

som-snytt


If you wish to suppress this warning, just add into your import section:

import scala.language.higherKinds
like image 30
Dmitry Bespalov Avatar answered Sep 22 '22 03:09

Dmitry Bespalov