@@ -46,6 +46,17 @@ data TextConstraint
4646 | TEnum [Symbol]
4747 deriving (Generic)
4848
49+
50+data DemotedTextConstraint
51+ = DTEq Integer
52+ | DTLt Integer
53+ | DTLe Integer
54+ | DTGt Integer
55+ | DTGe Integer
56+ | DTRegex Text
57+ | DTEnum [Text]
58+ deriving (Generic)
59+
4960data instance Sing (tc :: TextConstraint) where
5061 STEq :: Sing n -> Sing ('TEq n)
5162 STLt :: Sing n -> Sing ('TLt n)
@@ -79,6 +90,14 @@ data NumberConstraint
7990 | NEq Nat
8091 deriving (Generic)
8192
93+data DemotedNumberConstraint
94+ = DNLe Integer
95+ | DNLt Integer
96+ | DNGt Integer
97+ | DNGe Integer
98+ | DNEq Integer
99+ deriving (Generic)
100+
82101data instance Sing (nc :: NumberConstraint) where
83102 SNEq :: Sing n -> Sing ('NEq n)
84103 SNGt :: Sing n -> Sing ('NGt n)
@@ -102,6 +121,10 @@ data ArrayConstraint
102121 = AEq Nat
103122 deriving (Generic)
104123
124+data DemotedArrayConstraint
125+ = DAEq Integer
126+ deriving (Generic)
127+
105128data instance Sing (ac :: ArrayConstraint) where
106129 SAEq :: Sing n -> Sing ('AEq n)
107130
@@ -118,6 +141,15 @@ data Schema
118141 | SchemaOptional Schema
119142 deriving (Generic)
120143
144+data DemotedSchema
145+ = DSchemaText [DemotedTextConstraint]
146+ | DSchemaNumber [DemotedNumberConstraint]
147+ | DSchemaObject [(Text, DemotedSchema)]
148+ | DSchemaArray [DemotedArrayConstraint] DemotedSchema
149+ | DSchemaNull
150+ | DSchemaOptional DemotedSchema
151+ deriving (Generic)
152+
121153data instance Sing (schema :: Schema) where
122154 SSchemaText :: Sing tcs -> Sing ('SchemaText tcs)
123155 SSchemaNumber :: Sing ncs -> Sing ('SchemaNumber ncs)
@@ -146,6 +178,52 @@ instance Eq (Sing ('SchemaArray as s)) where _ == _ = True
146178instance Eq (Sing ('SchemaObject cs)) where _ == _ = True
147179instance Eq (Sing ('SchemaOptional s)) where _ == _ = True
148180
181+-- | One-way 'SingKind` variation
182+-- class SingKind' k where
183+-- type DemoteRep' k :: *
184+-- fromSing' :: Sing (a :: k) -> DemoteRep' k
185+
186+-- instance SingKind' TextConstraint where
187+-- type DemoteRep' TextConstraint = DemotedTextConstraint
188+-- fromSing' = \case
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)
195+-- STEnum s -> let
196+-- d :: Sing (s :: [Symbol]) -> [Text]
197+-- d SNil = []
198+-- d (SCons ss@SSym fs) = T.pack (symbolVal ss) : d fs
199+-- in DTEnum $ d s
200+
201+-- instance SingKind' NumberConstraint where
202+-- type DemoteRep' NumberConstraint = DemotedNumberConstraint
203+-- fromSing' = \case
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)
209+
210+-- instance SingKind' ArrayConstraint where
211+-- type DemoteRep' ArrayConstraint = DemotedArrayConstraint
212+-- fromSing' = \case
213+-- SAEq n -> withKnownNat n (DAEq $ natVal n)
214+
215+-- instance SingKind' Schema where
216+-- type DemoteRep' Schema = DemotedSchema
217+-- fromSing' = \case
218+-- SSchemaText tcs -> DSchemaText $ fromSing' tcs
219+ -- SchemaText [TextConstraint]
220+ -- SchemaNumber [NumberConstraint]
221+ -- SchemaObject [(Symbol, Schema)]
222+ -- SchemaArray [ArrayConstraint] Schema
223+ -- SchemaNull
224+ -- SchemaOptional Schema
225+
226+
149227data FieldRepr :: (Symbol, Schema) -> Type where
150228 FieldRepr
151229 :: (SingI schema, KnownSymbol name)