@@ -1,7 +1,6 @@
1{-# LANGUAGE AllowAmbiguousTypes #-}
1{-# LANGUAGE AllowAmbiguousTypes #-}
3−{-# LANGUAGE OverloadedLists #-}
2+{-# LANGUAGE OverloadedLists #-}
4−{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE OverloadedStrings #-}
5{-# OPTIONS_GHC -fprint-explicit-kinds #-}
4{-# OPTIONS_GHC -fprint-explicit-kinds #-}
7module Data.Schematic.Schema where
6module Data.Schematic.Schema where
@@ -13,7 +12,6 @@ import Data.Aeson.Types as J
13import Data.HashMap.Strict as H
12import Data.HashMap.Strict as H
14import Data.Kind
13import Data.Kind
15import Data.Maybe
14import Data.Maybe
16−import Data.Schematic.Generator
17import Data.Schematic.Instances ()
15import Data.Schematic.Instances ()
18import Data.Scientific
16import Data.Scientific
19import Data.Singletons.Prelude.List hiding (All, Union)
17import Data.Singletons.Prelude.List hiding (All, Union)
@@ -24,10 +22,8 @@ import Data.Union
24import Data.Vector as V
22import Data.Vector as V
25import Data.Vinyl hiding (Dict)
23import Data.Vinyl hiding (Dict)
26import qualified Data.Vinyl.TypeLevel as V
24import qualified Data.Vinyl.TypeLevel as V
28import GHC.Generics (Generic)
25import GHC.Generics (Generic)
30− (SomeNat(..), SomeSymbol(..), someNatVal, someSymbolVal)
26+import GHC.TypeLits (SomeNat(..), SomeSymbol(..), someSymbolVal, someNatVal)
31import Prelude as P
27import Prelude as P
32import Test.SmallCheck.Series
28import Test.SmallCheck.Series
@@ -51,33 +47,33 @@ data TextConstraint
51instance SingKind TextConstraint where
47instance SingKind TextConstraint where
52 type Demote TextConstraint = DemotedTextConstraint
48 type Demote TextConstraint = DemotedTextConstraint
53 fromSing = \case
49 fromSing = \case
54− STEq n -> withKnownNat n (DTEq . fromIntegral $ natVal n)
50+ STEq n -> withKnownNat n (DTEq $ natVal n)
55− STLt n -> withKnownNat n (DTLt . fromIntegral $ natVal n)
51+ STLt n -> withKnownNat n (DTLt $ natVal n)
56− STLe n -> withKnownNat n (DTLe . fromIntegral $ natVal n)
52+ STLe n -> withKnownNat n (DTLe $ natVal n)
57− STGt n -> withKnownNat n (DTGt . fromIntegral $ natVal n)
53+ STGt n -> withKnownNat n (DTGt $ natVal n)
58− STGe n -> withKnownNat n (DTGe . fromIntegral $ natVal n)
54+ STGe n -> withKnownNat n (DTGe $ natVal n)
59 STRegex s -> withKnownSymbol s (DTRegex $ T.pack $ symbolVal s)
55 STRegex s -> withKnownSymbol s (DTRegex $ T.pack $ symbolVal s)
60 STEnum s -> let
56 STEnum s -> let
61 d :: Sing (s :: [Symbol]) -> [Text]
57 d :: Sing (s :: [Symbol]) -> [Text]
62− d SNil = []
58+ d SNil = []
63 d (SCons ss@SSym fs) = T.pack (symbolVal ss) : d fs
59 d (SCons ss@SSym fs) = T.pack (symbolVal ss) : d fs
64 in DTEnum $ d s
60 in DTEnum $ d s
65 toSing = \case
61 toSing = \case
66 DTEq n -> case someNatVal n of
62 DTEq n -> case someNatVal n of
67 Just (SomeNat (_ :: Proxy n)) -> SomeSing (STEq (SNat :: Sing n))
63 Just (SomeNat (_ :: Proxy n)) -> SomeSing (STEq (SNat :: Sing n))
68− Nothing -> error "Negative singleton nat"
64+ Nothing -> error "Negative singleton nat"
69 DTLt n -> case someNatVal n of
65 DTLt n -> case someNatVal n of
70 Just (SomeNat (_ :: Proxy n)) -> SomeSing (STLt (SNat :: Sing n))
66 Just (SomeNat (_ :: Proxy n)) -> SomeSing (STLt (SNat :: Sing n))
71− Nothing -> error "Negative singleton nat"
67+ Nothing -> error "Negative singleton nat"
72 DTLe n -> case someNatVal n of
68 DTLe n -> case someNatVal n of
73 Just (SomeNat (_ :: Proxy n)) -> SomeSing (STLe (SNat :: Sing n))
69 Just (SomeNat (_ :: Proxy n)) -> SomeSing (STLe (SNat :: Sing n))
74− Nothing -> error "Negative singleton nat"
70+ Nothing -> error "Negative singleton nat"
75 DTGt n -> case someNatVal n of
71 DTGt n -> case someNatVal n of
76 Just (SomeNat (_ :: Proxy n)) -> SomeSing (STGt (SNat :: Sing n))
72 Just (SomeNat (_ :: Proxy n)) -> SomeSing (STGt (SNat :: Sing n))
77− Nothing -> error "Negative singleton nat"
73+ Nothing -> error "Negative singleton nat"
78 DTGe n -> case someNatVal n of
74 DTGe n -> case someNatVal n of
79 Just (SomeNat (_ :: Proxy n)) -> SomeSing (STGe (SNat :: Sing n))
75 Just (SomeNat (_ :: Proxy n)) -> SomeSing (STGe (SNat :: Sing n))
80− Nothing -> error "Negative singleton nat"
76+ Nothing -> error "Negative singleton nat"
81 DTRegex s -> case someSymbolVal (T.unpack s) of
77 DTRegex s -> case someSymbolVal (T.unpack s) of
82 SomeSymbol (_ :: Proxy n) -> SomeSing (STRegex (SSym :: Sing n))
78 SomeSymbol (_ :: Proxy n) -> SomeSing (STRegex (SSym :: Sing n))
83 DTEnum ss -> case toSing ss of
79 DTEnum ss -> case toSing ss of
@@ -91,7 +87,7 @@ data DemotedTextConstraint
91 | DTGe Integer
87 | DTGe Integer
92 | DTRegex Text
88 | DTRegex Text
93 | DTEnum [Text]
89 | DTEnum [Text]
94− deriving (Generic, Eq, Show)
90+ deriving (Generic)
96data instance Sing (tc :: TextConstraint) where
92data instance Sing (tc :: TextConstraint) where
97 STEq :: Sing n -> Sing ('TEq n)
93 STEq :: Sing n -> Sing ('TEq n)
@@ -132,7 +128,7 @@ data DemotedNumberConstraint
132 | DNGt Integer
128 | DNGt Integer
133 | DNGe Integer
129 | DNGe Integer
134 | DNEq Integer
130 | DNEq Integer
135− deriving (Generic, Eq, Show)
131+ deriving (Generic)
137data instance Sing (nc :: NumberConstraint) where
133data instance Sing (nc :: NumberConstraint) where
138 SNEq :: Sing n -> Sing ('NEq n)
134 SNEq :: Sing n -> Sing ('NEq n)
@@ -156,87 +152,51 @@ instance Eq (Sing ('NGe n)) where _ == _ = True
156instance SingKind NumberConstraint where
152instance SingKind NumberConstraint where
157 type Demote NumberConstraint = DemotedNumberConstraint
153 type Demote NumberConstraint = DemotedNumberConstraint
158 fromSing = \case
154 fromSing = \case
159− SNEq n -> withKnownNat n (DNEq . fromIntegral $ natVal n)
155+ SNEq n -> withKnownNat n (DNEq $ natVal n)
160− SNGt n -> withKnownNat n (DNGt . fromIntegral $ natVal n)
156+ SNGt n -> withKnownNat n (DNGt $ natVal n)
161− SNGe n -> withKnownNat n (DNGe . fromIntegral $ natVal n)
157+ SNGe n -> withKnownNat n (DNGe $ natVal n)
162− SNLt n -> withKnownNat n (DNLt . fromIntegral $ natVal n)
158+ SNLt n -> withKnownNat n (DNLt $ natVal n)
163− SNLe n -> withKnownNat n (DNLe . fromIntegral $ natVal n)
159+ SNLe n -> withKnownNat n (DNLe $ natVal n)
164 toSing = \case
160 toSing = \case
165 DNEq n -> case someNatVal n of
161 DNEq n -> case someNatVal n of
166 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SNEq (SNat :: Sing n))
162 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SNEq (SNat :: Sing n))
167− Nothing -> error "Negative singleton nat"
163+ Nothing -> error "Negative singleton nat"
168 DNGt n -> case someNatVal n of
164 DNGt n -> case someNatVal n of
169 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SNGt (SNat :: Sing n))
165 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SNGt (SNat :: Sing n))
170− Nothing -> error "Negative singleton nat"
166+ Nothing -> error "Negative singleton nat"
171 DNGe n -> case someNatVal n of
167 DNGe n -> case someNatVal n of
172 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SNGe (SNat :: Sing n))
168 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SNGe (SNat :: Sing n))
173− Nothing -> error "Negative singleton nat"
169+ Nothing -> error "Negative singleton nat"
174 DNLt n -> case someNatVal n of
170 DNLt n -> case someNatVal n of
175 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SNLt (SNat :: Sing n))
171 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SNLt (SNat :: Sing n))
176− Nothing -> error "Negative singleton nat"
172+ Nothing -> error "Negative singleton nat"
177 DNLe n -> case someNatVal n of
173 DNLe n -> case someNatVal n of
178 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SNLe (SNat :: Sing n))
174 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SNLe (SNat :: Sing n))
179− Nothing -> error "Negative singleton nat"
175+ Nothing -> error "Negative singleton nat"
181data ArrayConstraint
177data ArrayConstraint
182 = AEq Nat
178 = AEq Nat
187 deriving (Generic)
179 deriving (Generic)
189data DemotedArrayConstraint
181data DemotedArrayConstraint
190 = DAEq Integer
182 = DAEq Integer
195− deriving (Generic, Eq, Show)
183+ deriving (Generic)
197data instance Sing (ac :: ArrayConstraint) where
185data instance Sing (ac :: ArrayConstraint) where
198 SAEq :: Sing n -> Sing ('AEq n)
186 SAEq :: Sing n -> Sing ('AEq n)
199− SAGt :: Sing n -> Sing ('AGt n)
200− SAGe :: Sing n -> Sing ('AGe n)
201− SALt :: Sing n -> Sing ('ALt n)
202− SALe :: Sing n -> Sing ('ALe n)
204instance KnownNat n => SingI ('AEq n) where sing = SAEq sing
188instance KnownNat n => SingI ('AEq n) where sing = SAEq sing
205−instance KnownNat n => SingI ('AGt n) where sing = SAGt sing
206−instance KnownNat n => SingI ('AGe n) where sing = SAGe sing
207−instance KnownNat n => SingI ('ALt n) where sing = SALt sing
208−instance KnownNat n => SingI ('ALe n) where sing = SALe sing
210instance Eq (Sing ('AEq n)) where _ == _ = True
190instance Eq (Sing ('AEq n)) where _ == _ = True
211−instance Eq (Sing ('AGt n)) where _ == _ = True
212−instance Eq (Sing ('AGe n)) where _ == _ = True
213−instance Eq (Sing ('ALt n)) where _ == _ = True
214−instance Eq (Sing ('ALe n)) where _ == _ = True
216instance SingKind ArrayConstraint where
192instance SingKind ArrayConstraint where
217 type Demote ArrayConstraint = DemotedArrayConstraint
193 type Demote ArrayConstraint = DemotedArrayConstraint
218 fromSing = \case
194 fromSing = \case
219− SAEq n -> withKnownNat n (DAEq . fromIntegral $ natVal n)
195+ SAEq n -> withKnownNat n (DAEq $ natVal n)
220− SAGt n -> withKnownNat n (DAGt . fromIntegral $ natVal n)
221− SAGe n -> withKnownNat n (DAGe . fromIntegral $ natVal n)
222− SALt n -> withKnownNat n (DALt . fromIntegral $ natVal n)
223− SALe n -> withKnownNat n (DALe . fromIntegral $ natVal n)
224 toSing = \case
196 toSing = \case
225 DAEq n -> case someNatVal n of
197 DAEq n -> case someNatVal n of
226 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SAEq (SNat :: Sing n))
198 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SAEq (SNat :: Sing n))
227− Nothing -> error "Negative singleton nat"
228− DAGt n -> case someNatVal n of
229− Just (SomeNat (_ :: Proxy n)) -> SomeSing (SAGt (SNat :: Sing n))
230− Nothing -> error "Negative singleton nat"
231− DAGe n -> case someNatVal n of
232− Just (SomeNat (_ :: Proxy n)) -> SomeSing (SAGe (SNat :: Sing n))
233− Nothing -> error "Negative singleton nat"
234− DALt n -> case someNatVal n of
235− Just (SomeNat (_ :: Proxy n)) -> SomeSing (SALt (SNat :: Sing n))
236− Nothing -> error "Negative singleton nat"
237− DALe n -> case someNatVal n of
238− Just (SomeNat (_ :: Proxy n)) -> SomeSing (SALe (SNat :: Sing n))
239− Nothing -> error "Negative singleton nat"
199+ Nothing -> error "Negative singleton nat"
241data Schema
201data Schema
242 = SchemaText [TextConstraint]
202 = SchemaText [TextConstraint]
@@ -258,7 +218,7 @@ data DemotedSchema
258 | DSchemaNull
218 | DSchemaNull
259 | DSchemaOptional DemotedSchema
219 | DSchemaOptional DemotedSchema
260 | DSchemaUnion [DemotedSchema]
220 | DSchemaUnion [DemotedSchema]
261− deriving (Generic, Eq, Show)
221+ deriving (Generic)
263data instance Sing (schema :: Schema) where
223data instance Sing (schema :: Schema) where
264 SSchemaText :: Sing tcs -> Sing ('SchemaText tcs)
224 SSchemaText :: Sing tcs -> Sing ('SchemaText tcs)
@@ -373,31 +333,6 @@ data JsonRepr :: Schema -> Type where
373 ReprOptional :: Maybe (JsonRepr s) -> JsonRepr ('SchemaOptional s)
333 ReprOptional :: Maybe (JsonRepr s) -> JsonRepr ('SchemaOptional s)
374 ReprUnion :: Union JsonRepr (h ': tl) -> JsonRepr ('SchemaUnion (h ': tl))
334 ReprUnion :: Union JsonRepr (h ': tl) -> JsonRepr ('SchemaUnion (h ': tl))
376−instance (Monad m, Serial m Text, SingI cs)
377− => Serial m (JsonRepr ('SchemaText cs)) where
378− series = decDepth $ fmap ReprText $ textSeries $ fromSing (sing :: Sing cs)
380−instance (Monad m, Serial m Scientific, SingI cs)
381− => Serial m (JsonRepr ('SchemaNumber cs)) where
382− series = decDepth $ fmap ReprNumber
383− $ numberSeries $ fromSing (sing :: Sing cs)
385−instance Monad m => Serial m (JsonRepr 'SchemaNull) where
386− series = cons0 ReprNull
388−instance (Serial m (JsonRepr s), Serial m (V.Vector (JsonRepr s)), SingI cs)
389− => Serial m (JsonRepr ('SchemaArray cs s)) where
390− series = decDepth $ fmap ReprArray
391− $ arraySeries $ fromSing (sing :: Sing cs)
393−instance (Serial m (JsonRepr s))
394− => Serial m (JsonRepr ('SchemaOptional s)) where
395− series = cons1 ReprOptional
397−instance (Monad m, Serial m (Rec FieldRepr fs))
398− => Serial m (JsonRepr ('SchemaObject fs)) where
399− series = cons1 ReprObject
401-- | Move to the union package
336-- | Move to the union package
402instance Show (JsonRepr ('SchemaText cs)) where
337instance Show (JsonRepr ('SchemaText cs)) where
403 show (ReprText t) = "ReprText " P.++ show t
338 show (ReprText t) = "ReprText " P.++ show t
@@ -405,31 +340,39 @@ instance Show (JsonRepr ('SchemaText cs)) where
405instance Show (JsonRepr ('SchemaNumber cs)) where
340instance Show (JsonRepr ('SchemaNumber cs)) where
406 show (ReprNumber n) = "ReprNumber " P.++ show n
341 show (ReprNumber n) = "ReprNumber " P.++ show n
408−instance Show (JsonRepr 'SchemaBoolean) where
409− show (ReprBoolean n) = "ReprBoolean " P.++ show n
411instance Show (JsonRepr 'SchemaNull) where show _ = "ReprNull"
343instance Show (JsonRepr 'SchemaNull) where show _ = "ReprNull"
413instance Show (JsonRepr s) => Show (JsonRepr ('SchemaArray acs s)) where
345instance Show (JsonRepr s) => Show (JsonRepr ('SchemaArray acs s)) where
414 show (ReprArray v) = "ReprArray " P.++ show v
346 show (ReprArray v) = "ReprArray " P.++ show v
416−#if MIN_VERSION_base(4,12,0)
418− ( V.RecAll FieldRepr fs Show, RMap fs, ReifyConstraint Show FieldRepr fs
420− => Show (JsonRepr ('SchemaObject fs)) where
421− show (ReprObject fs) = "ReprObject " P.++ show fs
423instance V.RecAll FieldRepr fs Show => Show (JsonRepr ('SchemaObject fs)) where
348instance V.RecAll FieldRepr fs Show => Show (JsonRepr ('SchemaObject fs)) where
424 show (ReprObject fs) = "ReprObject " P.++ show fs
349 show (ReprObject fs) = "ReprObject " P.++ show fs
427instance Show (JsonRepr s) => Show (JsonRepr ('SchemaOptional s)) where
351instance Show (JsonRepr s) => Show (JsonRepr ('SchemaOptional s)) where
428 show (ReprOptional s) = "ReprOptional " P.++ show s
352 show (ReprOptional s) = "ReprOptional " P.++ show s
430−instance Show (Union JsonRepr (h ': tl))
354+instance (Monad m, Serial m Text)
431− => Show (JsonRepr ('SchemaUnion (h ': tl))) where
355+ => Serial m (JsonRepr ('SchemaText cs)) where
432− show (ReprUnion s) = "ReprUnion " P.++ show s
356+ series = cons1 ReprText
358+instance (Monad m, Serial m Scientific)
359+ => Serial m (JsonRepr ('SchemaNumber cs)) where
360+ series = cons1 ReprNumber
362+instance Monad m => Serial m (JsonRepr 'SchemaNull) where
363+ series = cons0 ReprNull
365+instance (Serial m (V.Vector (JsonRepr s)))
366+ => Serial m (JsonRepr ('SchemaArray cs s)) where
367+ series = cons1 ReprArray
369+instance (Serial m (JsonRepr s))
370+ => Serial m (JsonRepr ('SchemaOptional s)) where
371+ series = cons1 ReprOptional
373+instance (Monad m, Serial m (Rec FieldRepr fs))
374+ => Serial m (JsonRepr ('SchemaObject fs)) where
375+ series = cons1 ReprObject
434instance Eq (Rec FieldRepr fs) => Eq (JsonRepr ('SchemaObject fs)) where
377instance Eq (Rec FieldRepr fs) => Eq (JsonRepr ('SchemaObject fs)) where
435 ReprObject a == ReprObject b = a == b
378 ReprObject a == ReprObject b = a == b
@@ -440,9 +383,6 @@ instance Eq (JsonRepr ('SchemaText cs)) where
440instance Eq (JsonRepr ('SchemaNumber cs)) where
383instance Eq (JsonRepr ('SchemaNumber cs)) where
441 ReprNumber a == ReprNumber b = a == b
384 ReprNumber a == ReprNumber b = a == b
443−instance Eq (JsonRepr 'SchemaBoolean) where
444− ReprBoolean a == ReprBoolean b = a == b
446instance Eq (JsonRepr 'SchemaNull) where
386instance Eq (JsonRepr 'SchemaNull) where
447 ReprNull == ReprNull = True
387 ReprNull == ReprNull = True
@@ -452,51 +392,6 @@ instance Eq (JsonRepr s) => Eq (JsonRepr ('SchemaArray as s)) where
452instance Eq (JsonRepr s) => Eq (JsonRepr ('SchemaOptional s)) where
392instance Eq (JsonRepr s) => Eq (JsonRepr ('SchemaOptional s)) where
453 ReprOptional a == ReprOptional b = a == b
393 ReprOptional a == ReprOptional b = a == b
455−instance Eq (Union JsonRepr (h ': tl))
456− => Eq (JsonRepr ('SchemaUnion (h ': tl))) where
457− ReprUnion a == ReprUnion b = a == b
459−instance Ord (Rec FieldRepr fs) => Ord (JsonRepr ('SchemaObject fs)) where
460− ReprObject a `compare` ReprObject b = a `compare` b
462−instance Ord (JsonRepr ('SchemaText cs)) where
463− ReprText a `compare` ReprText b = a `compare` b
465−instance Ord (JsonRepr ('SchemaNumber cs)) where
466− ReprNumber a `compare` ReprNumber b = a `compare` b
468−instance Ord (JsonRepr 'SchemaBoolean) where
469− ReprBoolean a `compare` ReprBoolean b = a `compare` b
471−instance Ord (JsonRepr 'SchemaNull) where
474−instance Ord (JsonRepr s) => Ord (JsonRepr ('SchemaArray as s)) where
475− ReprArray a `compare` ReprArray b = a `compare` b
477−instance Ord (JsonRepr s) => Ord (JsonRepr ('SchemaOptional s)) where
478− ReprOptional a `compare` ReprOptional b = a `compare` b
480−instance Ord (Union JsonRepr (h ': tl))
481− => Ord (JsonRepr ('SchemaUnion (h ': tl))) where
482− ReprUnion a `compare` ReprUnion b = a `compare` b
484−instance IsList (JsonRepr ('SchemaArray cs s)) where
485− type Item (JsonRepr ('SchemaArray cs s)) = JsonRepr s
486− fromList = ReprArray . GHC.Exts.fromList
487− toList (ReprArray v) = GHC.Exts.toList v
489−instance Num (JsonRepr ('SchemaNumber cs)) where
490− ReprNumber a + ReprNumber b = ReprNumber $ a + b
491− ReprNumber a - ReprNumber b = ReprNumber $ a - b
492− ReprNumber a * ReprNumber b = ReprNumber $ a * b
493− abs (ReprNumber a) = ReprNumber $ abs a
494− signum (ReprNumber a) = ReprNumber $ signum a
495− fromInteger = ReprNumber . fromIntegral
497−instance IsString (JsonRepr ('SchemaText cs)) where
498− fromString = ReprText . fromString
500fromOptional
395fromOptional
501 :: SingI s
396 :: SingI s
502 => Sing ('SchemaOptional s)
397 => Sing ('SchemaOptional s)
@@ -542,25 +437,25 @@ instance SingI schema => J.FromJSON (JsonRepr schema) where
542 fieldRepr <- case s of
437 fieldRepr <- case s of
543 SSchemaText so -> case H.lookup fieldName h of
438 SSchemaText so -> case H.lookup fieldName h of
544 Just v -> withSingI so $ FieldRepr <$> parseJSON v
439 Just v -> withSingI so $ FieldRepr <$> parseJSON v
545− Nothing -> fail $ "No text field: " P.++ show fieldName
440+ Nothing -> fail "schematext"
546 SSchemaNumber so -> case H.lookup fieldName h of
441 SSchemaNumber so -> case H.lookup fieldName h of
547 Just v -> withSingI so $ FieldRepr <$> parseJSON v
442 Just v -> withSingI so $ FieldRepr <$> parseJSON v
548− Nothing -> fail $ "No number field: " P.++ show fieldName
443+ Nothing -> fail "schemanumber"
549 SSchemaBoolean -> case H.lookup fieldName h of
444 SSchemaBoolean -> case H.lookup fieldName h of
550 Just v -> FieldRepr <$> parseJSON v
445 Just v -> FieldRepr <$> parseJSON v
551− Nothing -> fail $ "No boolean field: " P.++ show fieldName
446+ Nothing -> fail "schemaboolean"
552 SSchemaNull -> case H.lookup fieldName h of
447 SSchemaNull -> case H.lookup fieldName h of
553 Just v -> FieldRepr <$> parseJSON v
448 Just v -> FieldRepr <$> parseJSON v
554− Nothing -> fail $ "No null field: " P.++ show fieldName
449+ Nothing -> fail "schemanull"
555 SSchemaArray sa sb -> case H.lookup fieldName h of
450 SSchemaArray sa sb -> case H.lookup fieldName h of
556 Just v -> withSingI sa $ withSingI sb $ FieldRepr <$> parseJSON v
451 Just v -> withSingI sa $ withSingI sb $ FieldRepr <$> parseJSON v
557− Nothing -> fail $ "No array field: " P.++ show fieldName
452+ Nothing -> fail "schemaarray"
558 SSchemaObject so -> case H.lookup fieldName h of
453 SSchemaObject so -> case H.lookup fieldName h of
559 Just v -> withSingI so $ FieldRepr <$> parseJSON v
454 Just v -> withSingI so $ FieldRepr <$> parseJSON v
560− Nothing -> fail $ "No object field" P.++ show fieldName
455+ Nothing -> fail "schemaobject"
561 SSchemaOptional so -> case H.lookup fieldName h of
456 SSchemaOptional so -> case H.lookup fieldName h of
562 Just v -> withSingI so $ FieldRepr <$> parseJSON v
457 Just v -> withSingI so $ FieldRepr <$> parseJSON v
563− Nothing -> withSingI so $ pure $ FieldRepr $ ReprOptional Nothing
458+ Nothing -> fail "schemaoptional"
564 SSchemaUnion ss -> withSingI ss $ FieldRepr <$> parseUnion ss value
459 SSchemaUnion ss -> withSingI ss $ FieldRepr <$> parseUnion ss value
565 (fieldRepr :&) <$> demoteFields tl h
460 (fieldRepr :&) <$> demoteFields tl h
566 ReprObject <$> withObject "Object" (demoteFields fs) value
461 ReprObject <$> withObject "Object" (demoteFields fs) value
@@ -572,7 +467,7 @@ instance J.ToJSON (JsonRepr a) where
572 toJSON (ReprText t) = J.String t
467 toJSON (ReprText t) = J.String t
573 toJSON (ReprNumber n) = J.Number n
468 toJSON (ReprNumber n) = J.Number n
574 toJSON (ReprOptional s) = case s of
469 toJSON (ReprOptional s) = case s of
575− Just v -> toJSON v
470+ Just v -> toJSON v
576 Nothing -> J.Null
471 Nothing -> J.Null
577 toJSON (ReprArray v) = J.Array $ toJSON <$> v
472 toJSON (ReprArray v) = J.Array $ toJSON <$> v
578 toJSON (ReprObject r) = J.Object . H.fromList . fold $ r
473 toJSON (ReprObject r) = J.Object . H.fromList . fold $ r