{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Data.Record.Generic.GHC (
ThroughLRGenerics(..)
, GhcMetadata(..)
, GhcFieldMetadata(..)
, ghcMetadata
) where
import Data.Kind
import Data.Proxy
import GHC.Generics hiding (Generic(..), Rep)
import GHC.TypeLits
import Data.Record.Generic
import qualified Data.Record.Generic.Rep as Rep
newtype ThroughLRGenerics a p = WrapThroughLRGenerics {
forall a p. ThroughLRGenerics a p -> a
unwrapThroughLRGenerics :: a
}
data GhcMetadata a = GhcMetadata {
forall a. GhcMetadata a -> Rep GhcFieldMetadata a
ghcMetadataFields :: Rep GhcFieldMetadata a
}
data GhcFieldMetadata :: Type -> Type where
GhcFieldMetadata :: forall (f :: Meta) (a :: Type).
Selector f
=> Proxy f -> GhcFieldMetadata a
withFieldMetadata :: forall (s :: Symbol) (r :: Type).
KnownSymbol s
=> Proxy s
-> FieldStrictness
-> (forall (f :: Meta). Selector f => Proxy f -> r)
-> r
withFieldMetadata :: forall (s :: Symbol) r.
KnownSymbol s =>
Proxy s
-> FieldStrictness
-> (forall (f :: Meta). Selector f => Proxy f -> r)
-> r
withFieldMetadata Proxy s
_ FieldStrictness
s forall (f :: Meta). Selector f => Proxy f -> r
k =
case FieldStrictness
s of
FieldStrictness
FieldLazy -> forall (f :: Meta). Selector f => Proxy f -> r
k (forall {k} (t :: k). Proxy t
Proxy @('MetaSel ('Just s) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy))
FieldStrictness
FieldStrict -> forall (f :: Meta). Selector f => Proxy f -> r
k (forall {k} (t :: k). Proxy t
Proxy @('MetaSel ('Just s) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict))
ghcMetadata :: Generic a => proxy a -> GhcMetadata a
ghcMetadata :: forall a (proxy :: * -> *). Generic a => proxy a -> GhcMetadata a
ghcMetadata proxy a
pa = GhcMetadata {
ghcMetadataFields :: Rep GhcFieldMetadata a
ghcMetadataFields = forall a (f :: * -> *) (g :: * -> *).
Generic a =>
(forall x. f x -> g x) -> Rep f a -> Rep g a
Rep.map forall x. FieldMetadata x -> GhcFieldMetadata x
ghcFieldMetadata Rep FieldMetadata a
recordFieldMetadata
}
where
Metadata{Int
String
Rep FieldMetadata a
recordFieldMetadata :: forall a. Metadata a -> Rep FieldMetadata a
recordSize :: forall a. Metadata a -> Int
recordConstructor :: forall a. Metadata a -> String
recordName :: forall a. Metadata a -> String
recordSize :: Int
recordConstructor :: String
recordName :: String
recordFieldMetadata :: Rep FieldMetadata a
..} = forall a (proxy :: * -> *). Generic a => proxy a -> Metadata a
metadata proxy a
pa
ghcFieldMetadata :: FieldMetadata x -> GhcFieldMetadata x
ghcFieldMetadata :: forall x. FieldMetadata x -> GhcFieldMetadata x
ghcFieldMetadata (FieldMetadata Proxy name
pName FieldStrictness
s) =
forall (s :: Symbol) r.
KnownSymbol s =>
Proxy s
-> FieldStrictness
-> (forall (f :: Meta). Selector f => Proxy f -> r)
-> r
withFieldMetadata Proxy name
pName FieldStrictness
s forall a b. (a -> b) -> a -> b
$ forall (f :: Meta) a. Selector f => Proxy f -> GhcFieldMetadata a
GhcFieldMetadata