You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Defining an instance for a higher kinded type class (e.g. Contravariant as opposed to Semigroup) in the type companion to an opaque type and trying to summon it implicitly causes the compiler to crash. Note that if the instance is imported explicitly the program will run correctly. But I don't think this should be necessary as implicit instances in the type companion should be available without explicit import and at the very least an an implicit not found error should be generated rather than the compiler crashing. See example below.
traitContravariant[F[_]] {
defcontramap[A, B](fa: F[A])(f: B=>A):F[B]
}
objectLibrary {
opaquetypeSet[A] =A=>BooleanobjectSet {
defsingleton[A](a: A):Set[A] =
_ == a
implicitclassSetOps[A](privatevalset:Set[A]) extendsAnyVal {
defcontains(a: A):Boolean=
set(a)
}
implicitvalsetContravariant:Contravariant[Set] =newContravariant[Set] {
defcontramap[A, B](fa: Set[A])(f: B=>A):Set[B] =
b => fa(f(b))
}
}
}
objectUserextendsApp {
importLibrary._//import Library.Set.setContravariant if this is imported the program will run correctlyvalF= implicitly[Contravariant[Set]]
valone=Set.singleton(1)
valchar=F.contramap(one)((s: String) => s.length)
assert(char.contains("a"))
assert(!char.contains("ab"))
}
The text was updated successfully, but these errors were encountered:
Higher kinded opaque aliases have a type lambda as right hand side. This
needs to be taken account of when computing the companion module of these
aliases.
Defining an instance for a higher kinded type class (e.g.
Contravariant
as opposed toSemigroup
) in the type companion to an opaque type and trying to summon it implicitly causes the compiler to crash. Note that if the instance is imported explicitly the program will run correctly. But I don't think this should be necessary as implicit instances in the type companion should be available without explicit import and at the very least an an implicit not found error should be generated rather than the compiler crashing. See example below.The text was updated successfully, but these errors were encountered: