@@ -46,6 +46,17 @@ data TextConstraint
46 | TEnum [Symbol]
46 | TEnum [Symbol]
47 deriving (Generic)
47 deriving (Generic)
50+data DemotedTextConstraint
49data instance Sing (tc :: TextConstraint) where
60data instance Sing (tc :: TextConstraint) where
50 STEq :: Sing n -> Sing ('TEq n)
61 STEq :: Sing n -> Sing ('TEq n)
51 STLt :: Sing n -> Sing ('TLt n)
62 STLt :: Sing n -> Sing ('TLt n)
@@ -79,6 +90,14 @@ data NumberConstraint
80 deriving (Generic)
91 deriving (Generic)
93+data DemotedNumberConstraint
82data instance Sing (nc :: NumberConstraint) where
101data instance Sing (nc :: NumberConstraint) where
83 SNEq :: Sing n -> Sing ('NEq n)
102 SNEq :: Sing n -> Sing ('NEq n)
84 SNGt :: Sing n -> Sing ('NGt n)
103 SNGt :: Sing n -> Sing ('NGt n)
@@ -102,6 +121,10 @@ data ArrayConstraint
102 = AEq Nat
121 = AEq Nat
103 deriving (Generic)
122 deriving (Generic)
124+data DemotedArrayConstraint
105data instance Sing (ac :: ArrayConstraint) where
128data instance Sing (ac :: ArrayConstraint) where
106 SAEq :: Sing n -> Sing ('AEq n)
129 SAEq :: Sing n -> Sing ('AEq n)
@@ -118,6 +141,15 @@ data Schema
118 | SchemaOptional Schema
141 | SchemaOptional Schema
119 deriving (Generic)
142 deriving (Generic)
145+ = DSchemaText [DemotedTextConstraint]
146+ | DSchemaNumber [DemotedNumberConstraint]
147+ | DSchemaObject [(Text, DemotedSchema)]
148+ | DSchemaArray [DemotedArrayConstraint] DemotedSchema
150+ | DSchemaOptional DemotedSchema
121data instance Sing (schema :: Schema) where
153data instance Sing (schema :: Schema) where
122 SSchemaText :: Sing tcs -> Sing ('SchemaText tcs)
154 SSchemaText :: Sing tcs -> Sing ('SchemaText tcs)
123 SSchemaNumber :: Sing ncs -> Sing ('SchemaNumber ncs)
155 SSchemaNumber :: Sing ncs -> Sing ('SchemaNumber ncs)
@@ -146,6 +178,52 @@ instance Eq (Sing ('SchemaArray as s)) where _ == _ = True
146instance Eq (Sing ('SchemaObject cs)) where _ == _ = True
178instance Eq (Sing ('SchemaObject cs)) where _ == _ = True
147instance Eq (Sing ('SchemaOptional s)) where _ == _ = True
179instance Eq (Sing ('SchemaOptional s)) where _ == _ = True
181+-- | One-way 'SingKind` variation
182+-- class SingKind' k where
183+-- type DemoteRep' k :: *
184+-- fromSing' :: Sing (a :: k) -> DemoteRep' k
186+-- instance SingKind' TextConstraint where
187+-- type DemoteRep' TextConstraint = DemotedTextConstraint
189+-- STEq n -> withKnownNat n (DTEq $ natVal n)
190+-- STLt n -> withKnownNat n (DTLt $ natVal n)
191+-- STLe n -> withKnownNat n (DTLe $ natVal n)
192+-- STGt n -> withKnownNat n (DTGt $ natVal n)
193+-- STGe n -> withKnownNat n (DTGe $ natVal n)
194+-- STRegex s -> withKnownSymbol s (DTRegex $ T.pack $ symbolVal s)
196+-- d :: Sing (s :: [Symbol]) -> [Text]
198+-- d (SCons ss@SSym fs) = T.pack (symbolVal ss) : d fs
201+-- instance SingKind' NumberConstraint where
202+-- type DemoteRep' NumberConstraint = DemotedNumberConstraint
204+-- SNLe n -> withKnownNat n (DNLe $ natVal n)
205+-- SNLt n -> withKnownNat n (DNLt $ natVal n)
206+-- SNGe n -> withKnownNat n (DNGe $ natVal n)
207+-- SNGt n -> withKnownNat n (DNGt $ natVal n)
208+-- SNEq n -> withKnownNat n (DNEq $ natVal n)
210+-- instance SingKind' ArrayConstraint where
211+-- type DemoteRep' ArrayConstraint = DemotedArrayConstraint
213+-- SAEq n -> withKnownNat n (DAEq $ natVal n)
215+-- instance SingKind' Schema where
216+-- type DemoteRep' Schema = DemotedSchema
218+-- SSchemaText tcs -> DSchemaText $ fromSing' tcs
219+ -- SchemaText [TextConstraint]
220+ -- SchemaNumber [NumberConstraint]
221+ -- SchemaObject [(Symbol, Schema)]
222+ -- SchemaArray [ArrayConstraint] Schema
224+ -- SchemaOptional Schema
149data FieldRepr :: (Symbol, Schema) -> Type where
227data FieldRepr :: (Symbol, Schema) -> Type where
150 FieldRepr
228 FieldRepr
151 :: (SingI schema, KnownSymbol name)
229 :: (SingI schema, KnownSymbol name)