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
Instances5Semigroup, Monoid, Consumable, Dupable, Movable
(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.Generics(Generic a, GConsumable (Rep a)) => Consumable (Generically a)Defined in linear-base-0.4.0 · Data.Unrestricted.Linear.Internal.Consumable(Generic a, GDupable (Rep a)) => Dupable (Generically a)Defined in linear-base-0.4.0 · Data.Unrestricted.Linear.Internal.Dupable(Generic a, GMovable (Rep a)) => Movable (Generically a)Defined in linear-base-0.4.0 · Data.Unrestricted.Linear.Internal.Movable