A datatype whose instances are defined generically, using the Generic representation. Generically1 is a higher-kinded version of Generically that uses Generic1.
Generic instances can be derived via Generically A using
-XDerivingVia.
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
import GHC.Generics (Generic)
data V4 a = V4 a a a a
deriving stock Generic
deriving (Semigroup, Monoid)
via Generically (V4 a)
This corresponds to Semigroup and Monoid instances defined by pointwise lifting:
instance Semigroup a => Semigroup (V4 a) where
(<>) :: V4 a -> V4 a -> V4 a
V4 a1 b1 c1 d1 <> V4 a2 b2 c2 d2 =
V4 (a1 <> a2) (b1 <> b2) (c1 <> c2) (d1 <> d2)
instance Monoid a => Monoid (V4 a) where
mempty :: V4 a
mempty = V4 mempty mempty mempty mempty
Historically this required modifying the type class to include
generic method definitions (-XDefaultSignatures) and deriving it
with the anyclass strategy (-XDeriveAnyClass). Having a /via
type/ like Generically decouples the instance from the type
class.
Constructors
Instances11Bounded, Enum, Eq, Ord, Read, Show, …
(Generic a, GBounded (Rep a)) => Bounded (Generically a)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Generically · orphan(Generic a, GEnum StandardEnum (Rep a)) => Enum (Generically a)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Generically · orphan(Generic a, Eq (Rep a ())) => Eq (Generically a)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Generically · orphan(Generic a, Ord (Rep a ())) => Ord (Generically a)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Generically · orphan(Generic a, GRead0 (Rep a)) => Read (Generically a)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Generically · orphan(Generic a, GShow0 (Rep a)) => Show (Generically a)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Generically · orphan(Generic a, Ord (Rep a ()), GIx (Rep a)) => Ix (Generically a)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Generically · orphanGeneric a => Generic (Generically a)Defined in generic-data-1.1.0.2 · Generic.Data.Internal.Generically · orphanThis is a hack to implicitly wrap/unwrap in the instances of Generically.
(Generic a, Semigroup (Rep a ())) => Semigroup (Generically a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Generic a, Monoid (Rep a ())) => Monoid (Generically a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Genericstype Rep (Generically a) = Rep aDefined in generic-data-1.1.0.2 · Generic.Data.Internal.Generically · orphan