@@ -1,7 +1,6 @@
11{-# LANGUAGE AllowAmbiguousTypes #-}
2−{-# LANGUAGE CPP #-}
3−{-# LANGUAGE OverloadedLists #-}
4−{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE OverloadedLists #-}
3+{-# LANGUAGE OverloadedStrings #-}
54{-# OPTIONS_GHC -fprint-explicit-kinds #-}
65
76module Data.Schematic.Schema where
@@ -13,8 +12,8 @@ import Data.Aeson.Types as J
1312import Data.HashMap.Strict as H
1413import Data.Kind
1514import Data.Maybe
16−import Data.Schematic.Generator
1715import Data.Schematic.Instances ()
16+import Data.Schematic.Generator
1817import Data.Scientific
1918import Data.Singletons.Prelude.List hiding (All, Union)
2019import Data.Singletons.TH
@@ -180,63 +179,27 @@ instance SingKind NumberConstraint where
180179
181180data ArrayConstraint
182181 = AEq Nat
183− | AGt Nat
184− | AGe Nat
185− | ALt Nat
186− | ALe Nat
187182 deriving (Generic)
188183
189184data DemotedArrayConstraint
190185 = DAEq Integer
191− | DAGt Integer
192− | DAGe Integer
193− | DALt Integer
194− | DALe Integer
195186 deriving (Generic, Eq, Show)
196187
197188data instance Sing (ac :: ArrayConstraint) where
198189 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)
203190
204191instance 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
209192
210193instance 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
215194
216195instance SingKind ArrayConstraint where
217196 type Demote ArrayConstraint = DemotedArrayConstraint
218197 fromSing = \case
219198 SAEq n -> withKnownNat n (DAEq . fromIntegral $ 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)
224199 toSing = \case
225200 DAEq n -> case someNatVal n of
226201 Just (SomeNat (_ :: Proxy n)) -> SomeSing (SAEq (SNat :: Sing n))
227202 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"
240203
241204data Schema
242205 = SchemaText [TextConstraint]
@@ -405,32 +368,17 @@ instance Show (JsonRepr ('SchemaText cs)) where
405368instance Show (JsonRepr ('SchemaNumber cs)) where
406369 show (ReprNumber n) = "ReprNumber " P.++ show n
407370
408−instance Show (JsonRepr 'SchemaBoolean) where
409− show (ReprBoolean n) = "ReprBoolean " P.++ show n
410−
411371instance Show (JsonRepr 'SchemaNull) where show _ = "ReprNull"
412372
413373instance Show (JsonRepr s) => Show (JsonRepr ('SchemaArray acs s)) where
414374 show (ReprArray v) = "ReprArray " P.++ show v
415375
416−#if MIN_VERSION_base(4,12,0)
417−instance
418− ( V.RecAll FieldRepr fs Show, RMap fs, ReifyConstraint Show FieldRepr fs
419− , RecordToList fs )
420− => Show (JsonRepr ('SchemaObject fs)) where
421− show (ReprObject fs) = "ReprObject " P.++ show fs
422−#else
423376instance V.RecAll FieldRepr fs Show => Show (JsonRepr ('SchemaObject fs)) where
424377 show (ReprObject fs) = "ReprObject " P.++ show fs
425−#endif
426378
427379instance Show (JsonRepr s) => Show (JsonRepr ('SchemaOptional s)) where
428380 show (ReprOptional s) = "ReprOptional " P.++ show s
429381
430−instance Show (Union JsonRepr (h ': tl))
431− => Show (JsonRepr ('SchemaUnion (h ': tl))) where
432− show (ReprUnion s) = "ReprUnion " P.++ show s
433−
434382instance Eq (Rec FieldRepr fs) => Eq (JsonRepr ('SchemaObject fs)) where
435383 ReprObject a == ReprObject b = a == b
436384
@@ -440,9 +388,6 @@ instance Eq (JsonRepr ('SchemaText cs)) where
440388instance Eq (JsonRepr ('SchemaNumber cs)) where
441389 ReprNumber a == ReprNumber b = a == b
442390
443−instance Eq (JsonRepr 'SchemaBoolean) where
444− ReprBoolean a == ReprBoolean b = a == b
445−
446391instance Eq (JsonRepr 'SchemaNull) where
447392 ReprNull == ReprNull = True
448393
@@ -452,10 +397,6 @@ instance Eq (JsonRepr s) => Eq (JsonRepr ('SchemaArray as s)) where
452397instance Eq (JsonRepr s) => Eq (JsonRepr ('SchemaOptional s)) where
453398 ReprOptional a == ReprOptional b = a == b
454399
455−instance Eq (Union JsonRepr (h ': tl))
456− => Eq (JsonRepr ('SchemaUnion (h ': tl))) where
457− ReprUnion a == ReprUnion b = a == b
458−
459400instance Ord (Rec FieldRepr fs) => Ord (JsonRepr ('SchemaObject fs)) where
460401 ReprObject a `compare` ReprObject b = a `compare` b
461402
@@ -465,9 +406,6 @@ instance Ord (JsonRepr ('SchemaText cs)) where
465406instance Ord (JsonRepr ('SchemaNumber cs)) where
466407 ReprNumber a `compare` ReprNumber b = a `compare` b
467408
468−instance Ord (JsonRepr 'SchemaBoolean) where
469− ReprBoolean a `compare` ReprBoolean b = a `compare` b
470−
471409instance Ord (JsonRepr 'SchemaNull) where
472410 compare _ _ = EQ
473411
@@ -477,10 +415,6 @@ instance Ord (JsonRepr s) => Ord (JsonRepr ('SchemaArray as s)) where
477415instance Ord (JsonRepr s) => Ord (JsonRepr ('SchemaOptional s)) where
478416 ReprOptional a `compare` ReprOptional b = a `compare` b
479417
480−instance Ord (Union JsonRepr (h ': tl))
481− => Ord (JsonRepr ('SchemaUnion (h ': tl))) where
482− ReprUnion a `compare` ReprUnion b = a `compare` b
483−
484418instance IsList (JsonRepr ('SchemaArray cs s)) where
485419 type Item (JsonRepr ('SchemaArray cs s)) = JsonRepr s
486420 fromList = ReprArray . GHC.Exts.fromList