Safe Haskell | None |
---|---|
Language | Haskell2010 |
Surgeries that are just coerce
.
Synopsis
- type Surgery (s :: *) (a :: *) = Generically (Surgery' s a)
- newtype Surgery' (s :: *) (a :: *) = Surgery' {
- unSurgery' :: a
- type family GSurgery (s :: *) (f :: k -> *) :: k -> *
- derecordify :: Coercible (GSurgery Derecordify f) f => Data f p -> Data (GSurgery Derecordify f) p
- underecordify :: Coercible f (GSurgery Derecordify f) => Data (GSurgery Derecordify f) p -> Data f p
- data Derecordify :: *
- type family GDerecordify (f :: k -> *) :: k -> *
- typeage :: Coercible (GSurgery Typeage f) f => Data f p -> Data (GSurgery Typeage f) p
- untypeage :: Coercible f (GSurgery Typeage f) => Data (GSurgery Typeage f) p -> Data f p
- data Typeage :: *
- renameFields :: forall rnm f p. Coercible (GSurgery (RenameFields rnm) f) f => Data f p -> Data (GSurgery (RenameFields rnm) f) p
- unrenameFields :: forall rnm f p. Coercible (GSurgery (RenameFields rnm) f) f => Data f p -> Data (GSurgery (RenameFields rnm) f) p
- renameConstrs :: forall rnm f p. Coercible (GSurgery (RenameConstrs rnm) f) f => Data f p -> Data (GSurgery (RenameConstrs rnm) f) p
- unrenameConstrs :: forall rnm f p. Coercible (GSurgery (RenameConstrs rnm) f) f => Data f p -> Data (GSurgery (RenameConstrs rnm) f) p
- data RenameFields (rnm :: *) :: *
- type family GRenameFields (rnm :: *) (f :: k -> *) :: k -> *
- data RenameConstrs (rnm :: *) :: *
- type family GRenameConstrs (rnm :: *) (f :: k -> *) :: k -> *
- type family (f :: *) @@ (s :: Symbol) :: Symbol
- data SId
- data SError
- data SConst (s :: Symbol)
- data SRename (xs :: [(Symbol, Symbol)]) (f :: *)
- type family SRename' (xs :: [(Symbol, Symbol)]) (f :: *) (s :: Symbol) where ...
- class UnifyRep (f :: k -> *) (g :: k -> *)
- onData :: (UnifyRep r s, UnifyRep s r) => p (Data r x) (Data s y) -> p (Data r x) (Data s y)
- data OnFields (f :: * -> *) :: *
- type family GOnFields (f :: * -> *) (g :: k -> *) :: k -> *
- type DOnFields (f :: * -> *) (a :: *) = Data (GSurgery (OnFields f) (Rep a)) ()
Surgery
type Surgery (s :: *) (a :: *) = Generically (Surgery' s a) Source #
Apply a microsurgery s
to a type a
for DerivingVia
.
Example
{-# LANGUAGE DerivingVia #-} -- The constructors must be visible. import Generic.Data.Microsurgery (Surgery
,Surgery'
(..),Generically
(..),Derecordify
) data T = T { unT :: Int } derivingShow
via (Surgery
Derecordify
T) -- T won't be shown as a record: -- show (T {unT = 3}) == "T 3"
newtype Surgery' (s :: *) (a :: *) Source #
See Surgery'
.
Surgery' | |
|
type family GSurgery (s :: *) (f :: k -> *) :: k -> * Source #
Apply a microsurgery represented by a symbol s
(declared as a dummy data
type) to a generic representation f
.
Instances
type GSurgery Derecordify (f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GSurgery Typeage (M1 D (MetaData nm md pk _nt) f :: k -> Type) Source # | |
type GSurgery (RenameFields rnm) (f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GSurgery (RenameConstrs rnm) (f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GSurgery (OnFields f) (g :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery |
Derecordify
derecordify :: Coercible (GSurgery Derecordify f) f => Data f p -> Data (GSurgery Derecordify f) p Source #
underecordify :: Coercible f (GSurgery Derecordify f) => Data (GSurgery Derecordify f) p -> Data f p Source #
data Derecordify :: * Source #
Forget that a type was declared using record syntax.
data Foo = Bar { baz :: Zap } -- becomes -- data Foo = Bar Zap
Concretely, set the last field of MetaCons
to False
and forget field
names.
This is a defunctionalized symbol, to be applied using GSurgery
.
Instances
type GSurgery Derecordify (f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery |
type family GDerecordify (f :: k -> *) :: k -> * Source #
Instances
type GDerecordify (U1 :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GDerecordify (V1 :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GDerecordify (f :*: g :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GDerecordify (f :+: g :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GDerecordify (M1 S (MetaSel _nm su ss ds) f :: k -> Type) Source # | |
type GDerecordify (M1 C (MetaCons nm fx _isRecord) f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery type GDerecordify (M1 C (MetaCons nm fx _isRecord) f :: k -> Type) = M1 C (MetaCons nm fx False) (GDerecordify f) | |
type GDerecordify (M1 D m f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery |
Type aging ("denewtypify")
Forget that a type is a newtype
. (The pun is that "aging" a type makes
it no longer "new".)
newtype Foo = Bar Baz -- becomes -- data Foo = Bar Baz
This is a defunctionalized symbol, to be applied using GSurgery
.
Renaming
renameFields :: forall rnm f p. Coercible (GSurgery (RenameFields rnm) f) f => Data f p -> Data (GSurgery (RenameFields rnm) f) p Source #
unrenameFields :: forall rnm f p. Coercible (GSurgery (RenameFields rnm) f) f => Data f p -> Data (GSurgery (RenameFields rnm) f) p Source #
renameConstrs :: forall rnm f p. Coercible (GSurgery (RenameConstrs rnm) f) f => Data f p -> Data (GSurgery (RenameConstrs rnm) f) p Source #
unrenameConstrs :: forall rnm f p. Coercible (GSurgery (RenameConstrs rnm) f) f => Data f p -> Data (GSurgery (RenameConstrs rnm) f) p Source #
data RenameFields (rnm :: *) :: * Source #
Rename fields using the function rnm
given as a parameter.
data Foo = Bar { baz :: Zap } -- becomes, renaming "baz" to "bag" -- data Foo = Bar { bag :: Zap }
This is a defunctionalized symbol, to be applied using GSurgery
.
Instances
type GSurgery (RenameFields rnm) (f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery |
type family GRenameFields (rnm :: *) (f :: k -> *) :: k -> * Source #
Instances
type GRenameFields rnm (U1 :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GRenameFields rnm (V1 :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GRenameFields rnm (f :*: g :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GRenameFields rnm (f :+: g :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GRenameFields rnm (M1 C m f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GRenameFields rnm (M1 D m f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GRenameFields rnm (M1 S (MetaSel (Just nm) su ss ds) f :: k -> Type) Source # | |
data RenameConstrs (rnm :: *) :: * Source #
Rename constructors using the function rnm
given as a parameter.
data Foo = Bar { baz :: Zap } -- becomes, renaming "Bar" to "Car" -- data Foo = Car { baz :: Zap }
This is a defunctionalized symbol, to be applied using GSurgery
.
Instances
type GSurgery (RenameConstrs rnm) (f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery |
type family GRenameConstrs (rnm :: *) (f :: k -> *) :: k -> * Source #
Instances
type GRenameConstrs rnm (V1 :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GRenameConstrs rnm (f :*: g :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GRenameConstrs rnm (f :+: g :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GRenameConstrs rnm (M1 D m f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
type GRenameConstrs rnm (M1 C (MetaCons nm fi ir) f :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery |
Defining symbol functions
type family (f :: *) @@ (s :: Symbol) :: Symbol Source #
f @@ s
is the application of a type-level function symbolized by f
to a s ::
.Symbol
A function FooToBar
can be defined as follows:
data FooToBar
type instance FooToBar @@
"foo" = "bar"
Empty function (compile-time error when applied).
data SRename (xs :: [(Symbol, Symbol)]) (f :: *) Source #
Define a function for a fixed set of strings, and fall back to f
for the others.
type family SRename' (xs :: [(Symbol, Symbol)]) (f :: *) (s :: Symbol) where ... Source #
Closed type family for SRename
.
Other
class UnifyRep (f :: k -> *) (g :: k -> *) Source #
Unify the "spines" of two generic representations (the "spine" is everything except the field types).
Instances
g' ~ (V1 :: k -> Type) => UnifyRep (V1 :: k -> Type) (g' :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
g' ~ (U1 :: k -> Type) => UnifyRep (U1 :: k -> Type) (g' :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
g' ~ (K1 i b :: k -> Type) => UnifyRep (K1 i a :: k -> Type) (g' :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
(g' ~ (g1 :*: g2), UnifyRep f1 g1, UnifyRep f2 g2) => UnifyRep (f1 :*: f2 :: k -> Type) (g' :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
(g' ~ (g1 :+: g2), UnifyRep f1 g1, UnifyRep f2 g2) => UnifyRep (f1 :+: f2 :: k -> Type) (g' :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery | |
(g' ~ M1 s c g, UnifyRep f g) => UnifyRep (M1 s c f :: k -> Type) (g' :: k -> Type) Source # | |
Defined in Generic.Data.Internal.Microsurgery |
onData :: (UnifyRep r s, UnifyRep s r) => p (Data r x) (Data s y) -> p (Data r x) (Data s y) Source #
onData :: _ => (Data r x -> Data s y) -> (Data r x -> Data s y) -- possible specialization
Can be used with generic-lens
for type-changing field updates with field_
(and possibly other generic optics).
A specialization of the identity function to be used to fix types
of functions on Data
, unifying the "spines" of input and output generic
representations (the "spine" is everything except field types, which may
thus change).
data OnFields (f :: * -> *) :: * Source #
Apply a type constructor f
to every field type of a generic
representation r
.
This is a defunctionalized symbol, to be applied using GSurgery
.
type family GOnFields (f :: * -> *) (g :: k -> *) :: k -> * Source #