@@ -46,11 +46,11 @@ data TextConstraint
4646 deriving (Generic)
4747
4848data instance Sing (tc :: TextConstraint) where
49− STEq :: (KnownNat n) => Sing n -> Sing ('TEq n)
50− STLe :: (KnownNat n) => Sing n -> Sing ('TLe n)
51− STGt :: (KnownNat n) => Sing n -> Sing ('TGt n)
52− STRegex :: (KnownSymbol s, SingI s) => Sing s -> Sing ('TRegex s)
53− STEnum :: (All KnownSymbol ss, SingI ss) => Sing ss -> Sing ('TEnum ss)
49+ STEq :: Sing n -> Sing ('TEq n)
50+ STLe :: Sing n -> Sing ('TLe n)
51+ STGt :: Sing n -> Sing ('TGt n)
52+ STRegex :: Sing s -> Sing ('TRegex s)
53+ STEnum :: All KnownSymbol ss => Sing ss -> Sing ('TEnum ss)
5454
5555instance (KnownNat n) => SingI ('TEq n) where sing = STEq sing
5656instance (KnownNat n) => SingI ('TGt n) where sing = STGt sing
@@ -71,9 +71,9 @@ data NumberConstraint
7171 deriving (Generic)
7272
7373data instance Sing (nc :: NumberConstraint) where
74− SNEq :: KnownNat n => Sing n -> Sing ('NEq n)
75− SNGt :: KnownNat n => Sing n -> Sing ('NGt n)
76− SNLe :: KnownNat n => Sing n -> Sing ('NLe n)
74+ SNEq :: Sing n -> Sing ('NEq n)
75+ SNGt :: Sing n -> Sing ('NGt n)
76+ SNLe :: Sing n -> Sing ('NLe n)
7777
7878instance KnownNat n => SingI ('NEq n) where sing = SNEq sing
7979instance KnownNat n => SingI ('NGt n) where sing = SNGt sing
@@ -88,7 +88,7 @@ data ArrayConstraint
8888 deriving (Generic)
8989
9090data instance Sing (ac :: ArrayConstraint) where
91− SAEq :: KnownNat n => Sing n -> Sing ('AEq n)
91+ SAEq :: Sing n -> Sing ('AEq n)
9292
9393instance KnownNat n => SingI ('AEq n) where sing = SAEq sing
9494
@@ -104,11 +104,11 @@ data Schema
104104 deriving (Generic)
105105
106106data instance Sing (schema :: Schema) where
107− SSchemaText :: SingI tcs => Sing tcs -> Sing ('SchemaText tcs)
108− SSchemaNumber :: SingI ncs => Sing ncs -> Sing ('SchemaNumber ncs)
109− SSchemaArray :: (SingI acs, SingI schema) => Sing acs -> Sing schema -> Sing ('SchemaArray acs schema)
110− SSchemaObject :: SingI fields => Sing fields -> Sing ('SchemaObject fields)
111− SSchemaOptional :: SingI s => Sing s -> Sing ('SchemaOptional s)
107+ SSchemaText :: Sing tcs -> Sing ('SchemaText tcs)
108+ SSchemaNumber :: Sing ncs -> Sing ('SchemaNumber ncs)
109+ SSchemaArray :: Sing acs -> Sing schema -> Sing ('SchemaArray acs schema)
110+ SSchemaObject :: Sing fields -> Sing ('SchemaObject fields)
111+ SSchemaOptional :: Sing s -> Sing ('SchemaOptional s)
112112 SSchemaNull :: Sing 'SchemaNull
113113
114114instance SingI sl => SingI ('SchemaText sl) where
@@ -238,37 +238,38 @@ fromOptional _ = parseJSON
238238
239239instance SingI schema => J.FromJSON (JsonRepr schema) where
240240 parseJSON value = case sing :: Sing schema of
241− SSchemaText _ -> withText "String" (pure . ReprText) value
242− SSchemaNumber _ -> withScientific "Number" (pure . ReprNumber) value
243− SSchemaNull -> case value of
241+ SSchemaText _ -> withText "String" (pure . ReprText) value
242+ SSchemaNumber _ -> withScientific "Number" (pure . ReprNumber) value
243+ SSchemaNull -> case value of
244244 J.Null -> pure ReprNull
245245 _ -> typeMismatch "Null" value
246− so@(SSchemaOptional _) -> ReprOptional <$> fromOptional so value
247− SSchemaArray _ _ -> withArray "Array" (fmap ReprArray . traverse parseJSON) value
248− SSchemaObject fs -> do
246+ so@(SSchemaOptional s) -> withSingI s $ ReprOptional <$> fromOptional so value
247+ SSchemaArray sa sb -> withSingI sa $ withSingI sb
248+ $ withArray "Array" (fmap ReprArray . traverse parseJSON) value
249+ SSchemaObject fs -> do
249250 let
250251 demoteFields :: SList s -> H.HashMap Text J.Value -> Parser (Rec FieldRepr s)
251252 demoteFields SNil _ = pure RNil
252253 demoteFields (SCons (STuple2 (n :: Sing fn) s) tl) h = withKnownSymbol n $ do
253254 let fieldName = T.pack $ symbolVal (Proxy @fn)
254255 fieldRepr <- case s of
255− SSchemaText _ -> case H.lookup fieldName h of
256− Just v -> FieldRepr <$> parseJSON v
256+ SSchemaText so -> case H.lookup fieldName h of
257+ Just v -> withSingI so $ FieldRepr <$> parseJSON v
257258 Nothing -> fail "schematext"
258− SSchemaNumber _ -> case H.lookup fieldName h of
259− Just v -> FieldRepr <$> parseJSON v
259+ SSchemaNumber so -> case H.lookup fieldName h of
260+ Just v -> withSingI so $ FieldRepr <$> parseJSON v
260261 Nothing -> fail "schemanumber"
261262 SSchemaNull -> case H.lookup fieldName h of
262263 Just v -> FieldRepr <$> parseJSON v
263264 Nothing -> fail "schemanull"
264− SSchemaArray _ _ -> case H.lookup fieldName h of
265− Just v -> FieldRepr <$> parseJSON v
265+ SSchemaArray sa sb -> case H.lookup fieldName h of
266+ Just v -> withSingI sa $ withSingI sb $ FieldRepr <$> parseJSON v
266267 Nothing -> fail "schemaarray"
267− SSchemaObject _ -> case H.lookup fieldName h of
268− Just v -> FieldRepr <$> parseJSON v
268+ SSchemaObject so -> case H.lookup fieldName h of
269+ Just v -> withSingI so $ FieldRepr <$> parseJSON v
269270 Nothing -> fail "schemaobject"
270− SSchemaOptional _ -> case H.lookup fieldName h of
271− Just v -> FieldRepr <$> parseJSON v
271+ SSchemaOptional so -> case H.lookup fieldName h of
272+ Just v -> withSingI so $ FieldRepr <$> parseJSON v
272273 Nothing -> fail "schemaoptional"
273274 (fieldRepr :&) <$> demoteFields tl h
274275 ReprObject <$> withObject "Object" (demoteFields fs) value