I have some datatypes with multiple fields, for which I’d like to derive Binary
and similar instances, based on DeriveAnyClass
and Generic
. However, some field in my type doesn’t have a Binary
instance, so automatic deriving fails.
I could of course replace this field with one of a newtype
type wrapping the original one, but this complicates usage of my datatype quite a bit, always need to (un)wrap the newtype
.
I could provide an orphan Binary
instance for the field type, but that’s to be avoided. I’m aware of the generic-override
package which could allow me to wrap a newtype
around the field just for the instance generation, then have a Binary
instance of said newtype
, but this would still require me to have orphan instances, in this case for Binary (Override ...)
, so this just pushed the problem forward.
Am I missing something? Is there a way to wrap one or more fields (i.e., not the whole structure as a deriving via
approach would allow for) with a newtype
only for the derived code, without introducing any orphans at all?