This issue is motivated by the Caliban library, which defines a Schema typeclass like this:
abstract class Schema[-R, T]
R can be different for different T, but we can combine heterogenous instances. For example, for some case class with fields that have corresponding instances Schema[R1, Field1] and Schema[R2, Field2] we can build a Schema[R1 & R2, SomeCaseClass]. However, as it stands right now, we can't easily derive it using Magnolia, because we have Schema.Typeclass defined as a Schema[Any, *], so that is what gen produces.
The way Caliban "solves" this is by providing a GenericSchema helper to the library user, with its own specialized Typeclass. It gets awkward to use without giving up the way ZIO code tends to be structured. I won't get into details, suffice to say that I'd like to only have to rely on Schema.gen for derivation.
I imagine that everywhere where we use Typeclass (e.g. here that is what typeConstructor is bound to), we can instead use a narrower type. It's a bit awkward to explain, so I'll add a PR for Scala 2 shortly.
Does this change fit this library, or is it specifically geared towards invariant typeclasses? I feel like with the rise of ZIO we are likely to see more of covariance everywhere, so cases like this could get somewhat more common.
This issue is motivated by the Caliban library, which defines a
Schematypeclass like this:Rcan be different for differentT, but we can combine heterogenous instances. For example, for some case class with fields that have corresponding instancesSchema[R1, Field1]andSchema[R2, Field2]we can build aSchema[R1 & R2, SomeCaseClass]. However, as it stands right now, we can't easily derive it using Magnolia, because we haveSchema.Typeclassdefined as aSchema[Any, *], so that is whatgenproduces.The way Caliban "solves" this is by providing a
GenericSchemahelper to the library user, with its own specializedTypeclass. It gets awkward to use without giving up the way ZIO code tends to be structured. I won't get into details, suffice to say that I'd like to only have to rely onSchema.genfor derivation.I imagine that everywhere where we use
Typeclass(e.g. here that is whattypeConstructoris bound to), we can instead use a narrower type. It's a bit awkward to explain, so I'll add a PR for Scala 2 shortly.Does this change fit this library, or is it specifically geared towards invariant typeclasses? I feel like with the rise of ZIO we are likely to see more of covariance everywhere, so cases like this could get somewhat more common.