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
This is small example for showing what I want to say:
importlanguage.experimental.macrosimportmagnolia._importcats.ShowobjectShowDerivation {
typeTypeclass[T] =Show[T]
defcombine[T](ctx: CaseClass[Show, T]):Show[T] =newShow[T] {
defshow(value: T):String=thrownewException("Don't support combine for show derivation.")
}
defdispatch[T](ctx: SealedTrait[Show, T]):Show[T] =newShow[T] {
defshow(value: T):String=
ctx.dispatch(value)(sub => sub.typeclass.show(sub.cast(value)))
}
defgen[T]:Show[T] = macro Magnolia.gen[T]
}
sealedtraitMySealedTraitcaseclassMyCaseClass(a: Int) extendsMySealedTraitcaseobjectMyCaseObjectextendsMySealedTrait// There is the compile error:// magnolia: could not find Show.Typeclass for type Int// in parameter 'a' of product type ForFun.MyCaseClassvala=ShowDerivation.gen[MyCaseClass]
// There is no compile error.// I want to make a compilation fails here.valb=ShowDerivation.gen[MyCaseObject.type]
Currently, I use magnolia for an automatic materialization of sealed trait when materializations of derived types (case class and case object) are given manually.
In this usage of magnolia, I only need dispatch except combine. And I want to make a compilation fails if there is no materialization of any derived type to prevent mistakes.
I think it can be helpful in many cases to support the way to use only dispatch except combine safely.
The text was updated successfully, but these errors were encountered:
This is small example for showing what I want to say:
Currently, I use
magnolia
for an automatic materialization ofsealed trait
when materializations of derived types (case class
andcase object
) are given manually.In this usage of
magnolia
, I only needdispatch
exceptcombine
. And I want to make a compilation fails if there is no materialization of any derived type to prevent mistakes.I think it can be helpful in many cases to support the way to use only
dispatch
exceptcombine
safely.The text was updated successfully, but these errors were encountered: