generic-data-0.5.0.0: Utilities for GHC.Generics

Safe HaskellNone
LanguageHaskell2010

Generic.Data.Internal.Microsurgery

Contents

Description

Surgeries that are just coerce.

Synopsis

Derecordify

type family Derecordify (f :: k -> *) :: k -> * 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.

Instances
type Derecordify (U1 :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type Derecordify (U1 :: k -> Type) = (U1 :: k -> Type)
type Derecordify (V1 :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type Derecordify (V1 :: k -> Type) = (V1 :: k -> Type)
type Derecordify (f :*: g :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type Derecordify (f :*: g :: k -> Type) = Derecordify f :*: Derecordify g
type Derecordify (f :+: g :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type Derecordify (f :+: g :: k -> Type) = Derecordify f :+: Derecordify g
type Derecordify (M1 S (MetaSel _nm su ss ds) f :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type Derecordify (M1 S (MetaSel _nm su ss ds) f :: k -> Type) = M1 S (MetaSel (Nothing :: Maybe Symbol) su ss ds) f
type Derecordify (M1 C (MetaCons nm fx _isRecord) f :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type Derecordify (M1 C (MetaCons nm fx _isRecord) f :: k -> Type) = M1 C (MetaCons nm fx False) (Derecordify f)
type Derecordify (M1 D m f :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type Derecordify (M1 D m f :: k -> Type) = M1 D m (Derecordify f)

Type aging ("denewtypify")

typeage :: Coercible (Typeage f) f => Data f p -> Data (Typeage f) p Source #

untypeage :: Coercible f (Typeage f) => Data (Typeage f) p -> Data f p Source #

type family Typeage (f :: k -> *) :: k -> * Source #

Forget that a type is a newtype.

newtype Foo = Bar Baz

-- becomes --

data Foo = Bar Baz
Instances
type Typeage (M1 D (MetaData nm md pk _nt) f :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type Typeage (M1 D (MetaData nm md pk _nt) f :: k -> Type) = M1 D (MetaData nm md pk False) f

Renaming

renameFields :: forall rnm f p. Coercible (RenameFields rnm f) f => Data f p -> Data (RenameFields rnm f) p Source #

unrenameFields :: forall rnm f p. Coercible (RenameFields rnm f) f => Data f p -> Data (RenameFields rnm f) p Source #

renameConstrs :: forall rnm f p. Coercible (RenameConstrs rnm f) f => Data f p -> Data (RenameConstrs rnm f) p Source #

unrenameConstrs :: forall rnm f p. Coercible (RenameConstrs rnm f) f => Data f p -> Data (RenameConstrs rnm f) p Source #

type family RenameFields (rnm :: *) (f :: k -> *) :: k -> * 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 }
Instances
type RenameFields rnm (U1 :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type RenameFields rnm (U1 :: k -> Type) = (U1 :: k -> Type)
type RenameFields rnm (V1 :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type RenameFields rnm (V1 :: k -> Type) = (V1 :: k -> Type)
type RenameFields rnm (f :*: g :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type RenameFields rnm (f :*: g :: k -> Type) = RenameFields rnm f :*: RenameFields rnm g
type RenameFields rnm (f :+: g :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type RenameFields rnm (f :+: g :: k -> Type) = RenameFields rnm f :+: RenameFields rnm g
type RenameFields rnm (M1 C m f :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type RenameFields rnm (M1 C m f :: k -> Type) = M1 C m (RenameFields rnm f)
type RenameFields rnm (M1 D m f :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type RenameFields rnm (M1 D m f :: k -> Type) = M1 D m (RenameFields rnm f)
type RenameFields rnm (M1 S (MetaSel (Just nm) su ss ds) f :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type RenameFields rnm (M1 S (MetaSel (Just nm) su ss ds) f :: k -> Type) = M1 S (MetaSel (Just (rnm @@ nm)) su ss ds) f

type family RenameConstrs (rnm :: *) (f :: k -> *) :: k -> * 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 }
Instances
type RenameConstrs rnm (V1 :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type RenameConstrs rnm (V1 :: k -> Type) = (V1 :: k -> Type)
type RenameConstrs rnm (f :*: g :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type RenameConstrs rnm (f :*: g :: k -> Type) = RenameConstrs rnm f :*: RenameConstrs rnm g
type RenameConstrs rnm (f :+: g :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type RenameConstrs rnm (f :+: g :: k -> Type) = RenameConstrs rnm f :+: RenameConstrs rnm g
type RenameConstrs rnm (M1 D m f :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type RenameConstrs rnm (M1 D m f :: k -> Type) = M1 D m (RenameConstrs rnm f)
type RenameConstrs rnm (M1 C (MetaCons nm fi ir) f :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type RenameConstrs rnm (M1 C (MetaCons nm fi ir) f :: k -> Type) = M1 C (MetaCons (rnm @@ nm) fi ir) f

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"
Instances
type SError @@ s Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type SError @@ s = (TypeError (Text "Invalid name: " :<>: ShowType s) :: Symbol)
type SId @@ s Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type SId @@ s = s
type (SConst z) @@ _s Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type (SConst z) @@ _s = z
type (SRename xs f) @@ s Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type (SRename xs f) @@ s = SRename' xs f s

data SId Source #

Identity function Symbol -> Symbol.

Instances
type SId @@ s Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type SId @@ s = s

data SError Source #

Empty function (compile-time error when applied).

Instances
type SError @@ s Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type SError @@ s = (TypeError (Text "Invalid name: " :<>: ShowType s) :: Symbol)

data SConst (s :: Symbol) Source #

Constant function.

Instances
type (SConst z) @@ _s Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type (SConst z) @@ _s = z

data SRename (xs :: [(Symbol, Symbol)]) (f :: *) Source #

Define a function for a fixed set of strings, and fall back to f for the others.

Instances
type (SRename xs f) @@ s Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type (SRename xs f) @@ s = SRename' xs f s

type family SRename' (xs :: [(Symbol, Symbol)]) (f :: *) (s :: Symbol) where ... Source #

Closed type family for SRename.

Equations

SRename' '[] f s = f @@ s 
SRename' ('(s, t) ': _xs) _f s = t 
SRename' ('(_r, _t) ': xs) f s = SRename' xs f s 

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 # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

g' ~ (U1 :: k -> Type) => UnifyRep (U1 :: k -> Type) (g' :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

g' ~ (K1 i b :: k -> Type) => UnifyRep (K1 i a :: k -> Type) (g' :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

(g' ~ (g1 :*: g2), UnifyRep f1 g1, UnifyRep f2 g2) => UnifyRep (f1 :*: f2 :: k -> Type) (g' :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

(g' ~ (g1 :+: g2), UnifyRep f1 g1, UnifyRep f2 g2) => UnifyRep (f1 :+: f2 :: k -> Type) (g' :: k -> Type) Source # 
Instance details

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 # 
Instance details

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).

type family OnFields (f :: * -> *) (r :: k -> *) :: k -> * Source #

Apply a type constructor f to every field type of a generic representation r.

Instances
type OnFields f (V1 :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type OnFields f (V1 :: k -> Type) = (V1 :: k -> Type)
type OnFields f (U1 :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type OnFields f (U1 :: k -> Type) = (U1 :: k -> Type)
type OnFields f (K1 i a :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type OnFields f (K1 i a :: k -> Type) = (K1 i (f a) :: k -> Type)
type OnFields f (r :*: s :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type OnFields f (r :*: s :: k -> Type) = OnFields f r :*: OnFields f s
type OnFields f (r :+: s :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type OnFields f (r :+: s :: k -> Type) = OnFields f r :+: OnFields f s
type OnFields f (M1 s m r :: k -> Type) Source # 
Instance details

Defined in Generic.Data.Internal.Microsurgery

type OnFields f (M1 s m r :: k -> Type) = M1 s m (OnFields f r)

type DOnFields (f :: * -> *) (a :: *) = Data (OnFields f (Rep a)) () Source #

Apply a type constructor to every field type of a type a to make a synthetic type.