cats-mtl
cats-mtl copied to clipboard
Inconsistent use of def vs val in embedded typeclass
In Ask:
def applicative: Applicative[F]
In Censor:
val applicative: Applicative[F]
So if you define traits that extend both, like:
trait MyTrait[F[_], Env, Evt] extends Censor[F, Chain[Evt]] with Ask[F, Env]
trait MyTrait2[F[_], Env, Evt] extends Ask[F, Env] with Censor[F, Chain[Evt]]
The order becomes important. MyTrait2 compiles but MyTrait fails with:
stable, immutable value required to override:
[error] val applicative: cats.Applicative[F] (defined in trait Censor)
[error] with def applicative: cats.Applicative[F] (defined in trait Ask)
[error] trait MyTrait[F[_], Env, Evt] extends Censor[F, Chain[Evt]] with Ask[F, Env]
How about using the same pattern to avoid such issues?