{-# 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 {
ThroughLRGenerics a p -> a
unwrapThroughLRGenerics :: a
}
data GhcMetadata a = GhcMetadata {
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 :: 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 -> Proxy
('MetaSel
('Just s) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy)
-> r
forall (f :: Meta). Selector f => Proxy f -> r
k (Proxy
('MetaSel
('Just s) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy)
forall k (t :: k). Proxy t
Proxy @('MetaSel ('Just s) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy))
FieldStrictness
FieldStrict -> Proxy
('MetaSel
('Just s) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict)
-> r
forall (f :: Meta). Selector f => Proxy f -> r
k (Proxy
('MetaSel
('Just s) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict)
forall k (t :: k). Proxy t
Proxy @('MetaSel ('Just s) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict))
ghcMetadata :: Generic a => proxy a -> GhcMetadata a
ghcMetadata :: proxy a -> GhcMetadata a
ghcMetadata proxy a
pa = GhcMetadata :: forall a. Rep GhcFieldMetadata a -> GhcMetadata a
GhcMetadata {
ghcMetadataFields :: Rep GhcFieldMetadata a
ghcMetadataFields = (forall x. FieldMetadata x -> GhcFieldMetadata x)
-> Rep FieldMetadata a -> Rep GhcFieldMetadata a
forall a (f :: Type -> Type) (g :: Type -> Type).
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
..} = proxy a -> Metadata a
forall a (proxy :: Type -> Type).
Generic a =>
proxy a -> Metadata a
metadata proxy a
pa
ghcFieldMetadata :: FieldMetadata x -> GhcFieldMetadata x
ghcFieldMetadata :: FieldMetadata x -> GhcFieldMetadata x
ghcFieldMetadata (FieldMetadata Proxy name
pName FieldStrictness
s) =
Proxy name
-> FieldStrictness
-> (forall (f :: Meta).
Selector f =>
Proxy f -> GhcFieldMetadata x)
-> GhcFieldMetadata x
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 (f :: Meta). Selector f => Proxy f -> GhcFieldMetadata x)
-> GhcFieldMetadata x)
-> (forall (f :: Meta).
Selector f =>
Proxy f -> GhcFieldMetadata x)
-> GhcFieldMetadata x
forall a b. (a -> b) -> a -> b
$ forall (f :: Meta). Selector f => Proxy f -> GhcFieldMetadata x
forall (f :: Meta) a. Selector f => Proxy f -> GhcFieldMetadata a
GhcFieldMetadata