Welcome! Got a question? Do you have -Ypartial-unification turned on? Other FAQs: http://typelevel.org/cats/faq.html
Eq
instance for a parameterized type: https://scastie.scala-lang.org/UknDiddWSLul5NTLoMr7zAimport cats.Eq
final case class Thing[A](a: A)
object Thing {
implicit def eqThing[I: Eq]: Eq[Thing[I]] = Eq.fromUniversalEquals
}
parameter value evidence$1 in method eqThing is never used
Eq[I]
, but you don't use that knowledge - you delegate to a method that constructs an Eq instance without any knowledge of the underlying type: https://github.com/typelevel/cats/blob/main/kernel/src/main/scala/cats/kernel/Eq.scala#L106
Eq.instance
and in it you can use the Eq[I]
instance
I: Eq
syntax)
in this case you just want to delegate - what does it mean for two Thing[I]
to be equal? for their thing.a
to be equal.
And you have the Eq[I]
instance to compare just the a
s
implicit def eqThing[I: Eq]: Eq[Thing[I]]
This says "If I know how to check equality of things of type I
, I can also check equality of things of type Thing[I]
"
You just need to use Eq.instance
to wire things together
Eq.by
which is even simpler
implicit def eqThing[I: Eq]: Eq[Thing[I]] = Eq.by(_.a)
something like this
IO
is more modern than Haskell's
trait Foo { type X }
, and a value val foo: Foo
(but not var foo
or def foo
), then you can talk about the type foo.X