module Record where
import BasePrelude hiding (Proxy)
import Data.Functor.Identity
import GHC.TypeLits
import Foreign.Storable
import Foreign.Ptr (plusPtr)
import Control.Lens.Basic
import qualified Record.TH as TH
data FieldName (t :: Symbol)
class Field (n :: Symbol) a a' v v' | n a -> v, n a' -> v', n a v' -> a', n a' v -> a where
fieldLens :: FieldName n -> Lens a a' v v'
instance Field "1" (Identity v1) (Identity v1') v1 v1' where
fieldLens = const $ \f -> fmap Identity . f . runIdentity
return $ do
arity <- [2 .. 24]
fieldIndex <- [1 .. arity]
return $ TH.tupleFieldInstanceDec arity fieldIndex
type Field' n a v =
Field n a a v v
return $ do
arity <- [1 .. 24]
strict <- [False, True]
let
recordType =
TH.recordTypeDec strict arity
fieldInstances =
do
fieldIndex <- [1 .. arity]
return $ TH.recordFieldInstanceDec strict arity fieldIndex
storableInstance =
TH.recordStorableInstanceDec strict arity
in recordType : storableInstance : fieldInstances
return $ concat $ TH.recordConFunDecs <$> [False, True] <*> [1 .. 24]