Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
copies the metadata from the
FixupMetaData
a gGHC.Generics.
representation of Generic
a
to the
representation g
.
does something similar when FixupMetaData1
f gf
is an instance
of Any
Generic
and g
is a Rep1
. See the individual type documentation
for details.
This is intended to help users instantiate Rep
and Rep1
for types with
nonlinear or multiplicity-polymorphic fields.
Suggested use
You will need to derive a GHC.Generics.Generic
instance for the
type. This is used to obtain the correct metadata.
Next you need to construct a Rep
and/or Rep1
for your type, ignoring the
metadata.
Constructing the actual representations can be a bit annoying, but GHC can help.
For Rep
Once you have derived GHC.Generics.
for your
type, define a value likeGeneric
test :: Rep T a test = _
Then compile. The stripped representation you need will be in the error message.
For Rep1
Construct a type with the same shape as the one you wish to
instantiate, but with only linear fields. Strictness annotations
and UNPACK
pragmas are irrelevant here.
Instantiate Generics.Linear.
for the lookalike using
Generic1
deriveGeneric1
and follow the same procedure
as above (but with
, of course) to get a metadata-stripped
representation.Rep1
T
For either
To avoid confusion, replace at least the package and module names in the
representation with Any
. Wrap MP1
around any nonlinear/representation
polymorphic fields, just under the S1
type constructor. The first type
argument of MP1
will indicate the multiplicity.
Synopsis
- type FixupMetaData (a :: Type) (g :: Type -> Type) = Fixup (Rep a) g
- type FixupMetaData1 (f :: k -> Type) (g :: k -> Type) = Fixup1 (Rep (f Any)) g
- type family RemoveMetaData (f :: k -> Type) :: k -> Type where ...
Documentation
type FixupMetaData (a :: Type) (g :: Type -> Type) = Fixup (Rep a) g Source #
FixupMetaData a g
copies the metadata from the
GHC.Generics.
representation of Generic
a
to the
representation g
. It also checks that the structure of Rep a
is the
same as g
, except that g
may have MP1
applications under some S1
constructors.
Example
instanceGeneric
(Ur
a) where type Rep (Ur a) = FixupMetaData (Ur a) (D1 Any (C1 Any (S1 Any (MP1 'Many (Rec0 a)))))
type FixupMetaData1 (f :: k -> Type) (g :: k -> Type) = Fixup1 (Rep (f Any)) g Source #
FixupMetaData1 f g
copies the metadata from the
GHC.Generics.
representation of Generic
f
to the representation Any
g
. It also checks that the overall structure of
Rep (f
is the same as Any
)g
, but does not check that their fields
match.
Example
instanceGeneric1
Ur
where type Rep1 Ur = FixupMetaData1 Ur (D1 Any (C1 Any (S1 Any (MP1 'Many Par1))))
type family RemoveMetaData (f :: k -> Type) :: k -> Type where ... Source #
RemoveMetaData (D1 _c f) = D1 Any (RemoveMetaData f) | |
RemoveMetaData (C1 _c f) = C1 Any (RemoveMetaData f) | |
RemoveMetaData (S1 _c f) = S1 Any f | |
RemoveMetaData (f :*: g) = RemoveMetaData f :*: RemoveMetaData g | |
RemoveMetaData (f :+: g) = RemoveMetaData f :+: RemoveMetaData g | |
RemoveMetaData x = x |