gpt4 book ai didi

scala - typeclass 注释应该已经被 simulacrum 删除但没有

转载 作者:行者123 更新时间:2023-12-01 12:07:15 33 4
gpt4 key购买 nike

我正在尝试使用 Simulacrum 编写一个简单的类型类。这是我的 build.sbt

ThisBuild / scalaVersion     := "2.12.8"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / organization := "com.example"
ThisBuild / organizationName := "example"

lazy val root = (project in file("."))
.settings(
name := "functional",
autoCompilerPlugins := true,
libraryDependencies ++= Seq(
"com.github.mpilquist" %% "simulacrum" % "0.15.0",
compilerPlugin("org.spire-math" %% "kind-projector" % "0.9.9")
)
)

这是我的代码

import simulacrum._

@typeclass trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B) : F[B]
def lift[A, B](fa: F[A])(f: A => B) : F[A] => F[B] = fa => map(fa)(f)
def as[A, B](fa: F[A], b: => B) : F[B] = map(fa)(_ => b)
def void[A](fa: F[A]) : F[Unit] = as(fa, ())
}

但是我得到一个错误

typeclass annotation should have been removed by simulacrum but was not
[error] @typeclass trait Functor[F[_]] {
[error] ^
[error] one error found

最佳答案

你没有添加宏观天堂

addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)

https://github.com/mpilquist/simulacrum#including-simulacrum

关于scala - typeclass 注释应该已经被 simulacrum 删除但没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55328130/

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