binary icon indicating copy to clipboard operation
binary copied to clipboard

Add GenericBinary wrapper that can be used with DerivingVia

Open vapourismo opened this issue 4 years ago • 4 comments

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?

vapourismo avatar Apr 17 '20 20:04 vapourismo

@kolmodin ping

vapourismo avatar Apr 27 '20 21:04 vapourismo

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?

kolmodin avatar Apr 28 '20 18:04 kolmodin

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.

vapourismo avatar Apr 28 '20 20:04 vapourismo

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

Icelandjack avatar Jul 26 '21 14:07 Icelandjack