Open kl0tl opened 4 years ago
I'd quite like to retain the current class names so that we can avoid a breaking change. How about a Using
prefix for newtypes? We could potentially even only provide a single newtype here and hang all of the instances onto it:
newtype UsingGeneric a = UsingGeneric a
instance showGeneric :: Generic a => Show (UsingGeneric a) where [...]
instance boundedGeneric :: Generic a => Bounded (UsingGeneric a) where [...]
instance enumGeneric :: Generic a => Enum (UsingGeneric a) where [...]
and then:
data ABC = ABC
derive instance genericABC :: Generic ABC _
derive via (UsingGeneric ABC) instance showABC :: Show ABC
derive via (UsingGeneric ABC) instance boundedABC :: Bounded ABC
derive via (UsingGeneric ABC) instance enumABC :: Enum ABC
With deriving via and some newtypes we could simulate defaults methods and alleviate a bit the implementation of typeclasses with generic defaults.
For instance implementing
Show
,Enum
andBounded
:Could be a bit more compact:
Writing those newtypes is straightforward and I gladly volonteer. The only annoyance is how to name them:
GenericBounded
isn’t taken butGenericShow
andGenericEnum
refer to the typeclasses implemented by the generic representation.Would it be acceptable to rename the typeclasses to
GenericRep*
and keepGeneric*
for the newtypes? Or has someone a better naming scheme to propose?