In Scala 3 I can define a functor for state using type lambda:
given stateFunctor[S]: Functor[[A] =>> State[S, A]] with
override def map[A, B](a: State[S, A])(fx: A => B): State[S, B] = State(a.run.andThen { case (s, a) => (s, fx(a)) })
I would expect it to work with ?
or _
wildcard:
given stateFunctor[S]: Functor[State[S, ?]] with
override def map[A, B](a: State[S, A])(fx: A => B): State[S, B] = State(a.run.andThen { case (s, a) => (s, fx(a)) })
but I'm getting the following compilation error:
Type argument domain.State[S, ? <: AnyKind] does not have the same kind as its bound [_$1] given stateFunctor[S]: Functor[State[S, ? <: AnyKind]] with
Why doesn't it work? What am I missing? I thought Scala 3 supports kind-projector syntax for type wildcards.
Scala version: 3.1.3
If you need it, here are State
and Functor
definitions:
case class State[S, A](run:S => (S, A)):
def exec(s:S):S = run(s)._1
def eval(s:S):A = run(s)._2
trait Functor[F[_]]:
def map[A, B](a: F[A])(fx: A => B): F[B]
-Ykind-projector
is used only when using kind-projector (so basically in Scala 2) – AlinaGlobal / scalacOptions += "-Ykind-projector"
in build.sbt, but it didn't work – Alina