I believe my understanding on this is correct but I'd like to check. When creating typeclasses, it feels neater to have them take a single type parameter, like TypeClass[A]
. If the typeclass needs to be parameterized in other ways, abstract types can be used, and there is a comparison of the two approaches here:
Abstract types versus type parameters
So far as I have been able to figure out, one thing which is not mentioned in the link is that if using a type parameter, you can witness that the parameter implements a (different) typeclass, likeso:
trait IsValidForTC[A]
abstract class TCWithTypeParam[A, B] (implicit ev: IsValidForTC[B]) {}
If I use an abstract type, I cannot be sure that it implements IsValidForTC
:
abstract class TCWithAbstractType[A] (implicit ev: IsValidForTC[B]) {
type B
} //not found: Type B
If so then this makes sense, but this difference isn't mentioned in the link above so I'd like to check.
Thanks!