@@ -30,6 +30,7 @@ import qualified Data.Vinyl.TypeLevel as Vinyl
3030import Data.Vinyl.XRec (IsoHKD (HKD , toHKD , unHKD ))
3131import Foreign.Storable (Storable )
3232import GHC.TypeLits (KnownSymbol , Symbol , symbolVal )
33+ import Data.Data (Data (gfoldl , toConstr , dataTypeOf , gunfold ), Typeable , DataType , Constr , Fixity (Prefix , Infix ), mkDataType , constrIndex , mkConstr )
3334
3435-- FIXME this file is a big bin of random stuff, and should be at least organized if not split up.
3536
@@ -102,6 +103,33 @@ instance KnownSymbol s => IsoHKD Identity (s :-> a) where
102103 unHKD = Identity . Val
103104 toHKD (Identity (Val x)) = x
104105
106+ deriving stock instance (Typeable k , Data k , KnownSymbol s ) => Data (s :-> k )
107+
108+ rnilConstr :: Constr
109+ rnilConstr = mkConstr recDataType " RNil" [] Prefix
110+
111+ rconsConstr :: Constr
112+ rconsConstr = mkConstr recDataType " (:&)" [] Infix
113+
114+ recDataType :: DataType
115+ recDataType = mkDataType " Data.Vinyl.Core.Rec" [rnilConstr, rconsConstr]
116+
117+ instance Data (Record '[] ) where
118+ gfoldl _ z RNil = z RNil
119+ toConstr RNil = rnilConstr
120+ dataTypeOf _ = recDataType
121+ gunfold _ z c = case constrIndex c of
122+ 1 -> z RNil
123+ _ -> errorWithoutStackTrace " Data.Data.gunfold(Rec)"
124+
125+ instance (Data x , Typeable xs , Data (Record xs )) => Data (Record (x ': xs )) where
126+ gfoldl f z (x :& xs) = z (:&) `f` x `f` xs
127+ toConstr (_ :& _) = rconsConstr
128+ dataTypeOf _ = recDataType
129+ gunfold k z c = case constrIndex c of
130+ 2 -> k (k (z (:&) ))
131+ _ -> errorWithoutStackTrace " Data.Data.gunfold(Rec)"
132+
105133-- | Convenience function to make an @'Identity' (s ':->' a)@ with a particular symbol, used for named field construction.
106134--
107135-- For example:
0 commit comments