cats-mtl icon indicating copy to clipboard operation
cats-mtl copied to clipboard

Inconsistent use of def vs val in embedded typeclass

Open ghostdogpr opened this issue 5 years ago • 0 comments

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?

ghostdogpr avatar Oct 06 '20 01:10 ghostdogpr