gpt4 book ai didi

shapeless - Functor 缺少参数实例的隐式值(仅在 sbt clean 之后)

转载 作者:行者123 更新时间:2023-12-03 08:21:05 25 4
gpt4 key购买 nike

我用 Kittens ( https://github.com/milessabin/kittens ) 做了一些实验,但在编译我的代码时遇到了问题。我收到以下错误。

[error] ...danirey\scala\kittens\Kittens.scala:23: could not find implicit value for parameter instance: cats.Functor[danirey.scala.kittens.AdtDefns.Tree]
[error] val funct = Functor[Tree]
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed

完整文件如下

package danirey.scala.kittens

/**
* @author Dani
*/
import cats.Functor
import cats.syntax.AllSyntax
import cats.derived.functor._
import legacy._
import cats.derived.iterable.legacy._
import org.typelevel.discipline.scalatest.Discipline
import shapeless.cachedImplicit

object Kittens extends App {
val ft = new FunctorExperiment()
ft.print()
}

class FunctorExperiment extends AllSyntax {
import AdtDefns._

def print():Unit = {
val funct = Functor[Tree]
val tree: Tree[String] = Node(
Leaf("Reto"),
Node(
Leaf("Sandra"),
Leaf("Mike")
)
)

println(funct.map(tree)(_.length))
}
}

我在 ScalaTest 中使用了几乎相同的代码,它编译没有任何问题。

package danirey.scala.kittens

import cats.Functor
import cats.syntax.AllSyntax
import cats.derived.functor._
import legacy._
import cats.derived.iterable.legacy._
import org.scalatest.FunSuite
import org.typelevel.discipline.scalatest.Discipline
import shapeless.cachedImplicit

/**
* @author Dani
*/
class FunctorExperimentTest extends FunSuite with Discipline with AllSyntax {

import AdtDefns._

test("functors experiment") {
val funct = Functor[Tree]

val tree: Tree[String] = Node(
Leaf("Reto"),
Node(
Leaf("Sandra"),
Leaf("Mike")
)
)

println(funct.map(tree)(_.length))
}
}

我的 build.sbt 看起来如下 名称:=“无形实验”

version := "1.0-SNAPSHOT"

scalaVersion := "2.11.8"

exportJars := true

libraryDependencies ++= Seq(
"com.chuusai" % "shapeless_2.11" % "2.3.0",
"org.typelevel" % "kittens_2.11" % "1.0.0-M2",
"org.scalatest" %% "scalatest" % "3.0.0-M7" % "test"
)

scalacOptions ++= Seq(
"-feature",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked"
)

最有趣的是,它作为增量编译的一部分进行编译。

如果我注释第 16、23 和 32 行,然后执行“sbt compile”,然后再次删除注释并执行它编译的“sbt compile/package”,我什至可以执行程序。但是只要我运行“sbt clean”,它就不会再编译了。

AdtDefns 对象基本上是 https://github.com/milessabin/kittens/blob/master/core/src/test/scala/cats/derived/adtdefns.scala 的副本相关部分是

object AdtDefns {
sealed trait Tree[T]
final case class Leaf[T](t: T) extends Tree[T]
final case class Node[T](l: Tree[T], r: Tree[T]) extends Tree[T]
}

PS:如果有人可以为 scala-kittens 创建一个标签,那就太好了

最佳答案

@DaniRey 我们在项目中使用小猫,但只使用序列部分。我不知道有任何项目使用小猫派生。您的用户案例是什么?

关于shapeless - Functor 缺少参数实例的隐式值(仅在 sbt clean 之后),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36972351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com