binary
binary copied to clipboard
Add GenericBinary wrapper that can be used with DerivingVia
I think the examples highlight what this wrapper is supposed to accomplish.
-- Simple usage with DerivingVia:
data Foo = Foo Int String
deriving Generic
deriving Binary via GenericBinary Foo
-- When chaining multiple augmentations:
data Foo = Foo Int String
deriving Generic
deriving Binary via Augmentation1 (Augmentation2 (GenericBinary Foo))
I am conflicted on the name. Should it be GBinary or would that indicate it is supposed to be a class that implements Binary in terms of Generic?
@kolmodin ping
I haven't used deriving via. So there's not a common pattern for how to name the additional newtype?
Did I get it right that the first "simple usage" can just be done with deriving Binary and where it's useful is actually when chaining augmentations?
I haven't dealt with that many deriving-via patterns to call myself a pattern name expert, but I am more torn on whether it fits into the library.
Your observation is correct. The first pattern is trivial enough to be achievable using a simple deriving Binary when DeriveAnyClass is enabled.
The second one is where the utility starts. The scenario being that one wants to enhance the generic anyclass Binary instance for Foo.
If/when we get Generically it can serve as a common type of generic instances
type Foo :: Type
data Foo = Foo [Int] String
deriving
stock Generic
deriving (Semigroup, Monoid, Binary, ..)
via Generically Foo