@@ -13,7 +13,7 @@ import Data.HashMap.Strict as H
13import Data.Kind
13import Data.Kind
14import Data.Maybe
14import Data.Maybe
15import Data.Schematic.Instances ()
15import Data.Schematic.Instances ()
16−import Data.Schematic.Utils
16+
17import Data.Scientific
17import Data.Scientific
18import Data.Singletons.Prelude.List hiding (All)
18import Data.Singletons.Prelude.List hiding (All)
19import Data.Singletons.TH
19import Data.Singletons.TH
@@ -49,14 +49,14 @@ data instance Sing (tc :: TextConstraint) where
49 STEq :: (KnownNat n) => Sing n -> Sing ('TEq n)
49 STEq :: (KnownNat n) => Sing n -> Sing ('TEq n)
50 STLe :: (KnownNat n) => Sing n -> Sing ('TLe n)
50 STLe :: (KnownNat n) => Sing n -> Sing ('TLe n)
51 STGt :: (KnownNat n) => Sing n -> Sing ('TGt n)
51 STGt :: (KnownNat n) => Sing n -> Sing ('TGt n)
52− STRegex :: (KnownSymbol s, Known (Sing s)) => Sing s -> Sing ('TRegex s)
52+ STRegex :: (KnownSymbol s, SingI s) => Sing s -> Sing ('TRegex s)
53− STEnum :: (All KnownSymbol ss, Known (Sing ss)) => Sing ss -> Sing ('TEnum ss)
53+ STEnum :: (All KnownSymbol ss, SingI ss) => Sing ss -> Sing ('TEnum ss)
55−instance (KnownNat n) => Known (Sing ('TEq n)) where known = STEq known
55+instance (KnownNat n) => SingI ('TEq n) where sing = STEq sing
56−instance (KnownNat n) => Known (Sing ('TGt n)) where known = STGt known
56+instance (KnownNat n) => SingI ('TGt n) where sing = STGt sing
57−instance (KnownNat n) => Known (Sing ('TLe n)) where known = STLe known
57+instance (KnownNat n) => SingI ('TLe n) where sing = STLe sing
58−instance (KnownSymbol s, Known (Sing s)) => Known (Sing ('TRegex s)) where known = STRegex known
58+instance (KnownSymbol s, SingI s) => SingI ('TRegex s) where sing = STRegex sing
59−instance (All KnownSymbol ss, Known (Sing ss)) => Known (Sing ('TEnum ss)) where known = STEnum known
59+instance (All KnownSymbol ss, SingI ss) => SingI ('TEnum ss) where sing = STEnum sing
61instance Eq (Sing ('TEq n)) where _ == _ = True
61instance Eq (Sing ('TEq n)) where _ == _ = True
62instance Eq (Sing ('TLe n)) where _ == _ = True
62instance Eq (Sing ('TLe n)) where _ == _ = True
@@ -75,9 +75,9 @@ data instance Sing (nc :: NumberConstraint) where
75 SNGt :: KnownNat n => Sing n -> Sing ('NGt n)
75 SNGt :: KnownNat n => Sing n -> Sing ('NGt n)
76 SNLe :: KnownNat n => Sing n -> Sing ('NLe n)
76 SNLe :: KnownNat n => Sing n -> Sing ('NLe n)
78−instance KnownNat n => Known (Sing ('NEq n)) where known = SNEq known
78+instance KnownNat n => SingI ('NEq n) where sing = SNEq sing
79−instance KnownNat n => Known (Sing ('NGt n)) where known = SNGt known
79+instance KnownNat n => SingI ('NGt n) where sing = SNGt sing
80−instance KnownNat n => Known (Sing ('NLe n)) where known = SNLe known
80+instance KnownNat n => SingI ('NLe n) where sing = SNLe sing
82instance Eq (Sing ('NEq n)) where _ == _ = True
82instance Eq (Sing ('NEq n)) where _ == _ = True
83instance Eq (Sing ('NLe n)) where _ == _ = True
83instance Eq (Sing ('NLe n)) where _ == _ = True
@@ -90,7 +90,7 @@ data ArrayConstraint
90data instance Sing (ac :: ArrayConstraint) where
90data instance Sing (ac :: ArrayConstraint) where
91 SAEq :: KnownNat n => Sing n -> Sing ('AEq n)
91 SAEq :: KnownNat n => Sing n -> Sing ('AEq n)
93−instance KnownNat n => Known (Sing ('AEq n)) where known = SAEq known
93+instance KnownNat n => SingI ('AEq n) where sing = SAEq sing
95instance Eq (Sing ('AEq n)) where _ == _ = True
95instance Eq (Sing ('AEq n)) where _ == _ = True
@@ -104,25 +104,25 @@ data Schema
104 deriving (Generic)
104 deriving (Generic)
106data instance Sing (schema :: Schema) where
106data instance Sing (schema :: Schema) where
107− SSchemaText :: Known (Sing tcs) => Sing tcs -> Sing ('SchemaText tcs)
107+ SSchemaText :: SingI tcs => Sing tcs -> Sing ('SchemaText tcs)
108− SSchemaNumber :: Known (Sing ncs) => Sing ncs -> Sing ('SchemaNumber ncs)
108+ SSchemaNumber :: SingI ncs => Sing ncs -> Sing ('SchemaNumber ncs)
109− SSchemaArray :: (Known (Sing acs), Known (Sing schema)) => Sing acs -> Sing schema -> Sing ('SchemaArray acs schema)
109+ SSchemaArray :: (SingI acs, SingI schema) => Sing acs -> Sing schema -> Sing ('SchemaArray acs schema)
110− SSchemaObject :: Known (Sing fields) => Sing fields -> Sing ('SchemaObject fields)
110+ SSchemaObject :: SingI fields => Sing fields -> Sing ('SchemaObject fields)
111− SSchemaOptional :: Known (Sing s) => Sing s -> Sing ('SchemaOptional s)
111+ SSchemaOptional :: SingI s => Sing s -> Sing ('SchemaOptional s)
112 SSchemaNull :: Sing 'SchemaNull
112 SSchemaNull :: Sing 'SchemaNull
114−instance Known (Sing sl) => Known (Sing ('SchemaText sl)) where
114+instance SingI sl => SingI ('SchemaText sl) where
115− known = SSchemaText known
115+ sing = SSchemaText sing
116−instance Known (Sing sl) => Known (Sing ('SchemaNumber sl)) where
116+instance SingI sl => SingI ('SchemaNumber sl) where
117− known = SSchemaNumber known
117+ sing = SSchemaNumber sing
118−instance Known (Sing 'SchemaNull) where
118+instance SingI 'SchemaNull where
119− known = SSchemaNull
119+ sing = SSchemaNull
120−instance (Known (Sing ac), Known (Sing s)) => Known (Sing ('SchemaArray ac s)) where
120+instance (SingI ac, SingI s) => SingI ('SchemaArray ac s) where
121− known = SSchemaArray known known
121+ sing = SSchemaArray sing sing
122−instance Known (Sing stl) => Known (Sing ('SchemaObject stl)) where
122+instance SingI stl => SingI ('SchemaObject stl) where
123− known = SSchemaObject known
123+ sing = SSchemaObject sing
124−instance Known (Sing s) => Known (Sing ('SchemaOptional s)) where
124+instance SingI s => SingI ('SchemaOptional s) where
125− known = SSchemaOptional known
125+ sing = SSchemaOptional sing
127instance Eq (Sing ('SchemaText cs)) where _ == _ = True
127instance Eq (Sing ('SchemaText cs)) where _ == _ = True
128instance Eq (Sing ('SchemaNumber cs)) where _ == _ = True
128instance Eq (Sing ('SchemaNumber cs)) where _ == _ = True
@@ -133,7 +133,7 @@ instance Eq (Sing ('SchemaOptional s)) where _ == _ = True
134data FieldRepr :: (Symbol, Schema) -> Type where
134data FieldRepr :: (Symbol, Schema) -> Type where
135 FieldRepr
135 FieldRepr
136− :: (Known (Sing schema), KnownSymbol name)
136+ :: (SingI schema, KnownSymbol name)
137 => JsonRepr schema
137 => JsonRepr schema
138 -> FieldRepr '(name, schema)
138 -> FieldRepr '(name, schema)
@@ -146,10 +146,10 @@ knownFieldName _ = T.pack $ symbolVal (Proxy @fieldName)
147knownFieldSchema
147knownFieldSchema
148 :: forall proxy fieldName schema
148 :: forall proxy fieldName schema
149− . Known (Sing schema)
149+ . SingI schema
150 => proxy '(fieldName, schema)
150 => proxy '(fieldName, schema)
151 -> Sing schema
151 -> Sing schema
152−knownFieldSchema _ = known
152+knownFieldSchema _ = sing
154deriving instance Show (JsonRepr schema) => Show (FieldRepr '(name, schema))
154deriving instance Show (JsonRepr schema) => Show (FieldRepr '(name, schema))
@@ -158,7 +158,7 @@ instance Eq (JsonRepr schema) => Eq (FieldRepr '(name, schema)) where
160 ( KnownSymbol name
160 ( KnownSymbol name
161− , Known (Sing schema)
161+ , SingI schema
162 , Serial m (JsonRepr schema) )
162 , Serial m (JsonRepr schema) )
163 => Serial m (FieldRepr '(name, schema)) where
163 => Serial m (FieldRepr '(name, schema)) where
164 series = FieldRepr <$> series
164 series = FieldRepr <$> series
@@ -230,14 +230,14 @@ instance Eq (JsonRepr s) => Eq (JsonRepr ('SchemaOptional s)) where
230 ReprOptional a == ReprOptional b = a == b
230 ReprOptional a == ReprOptional b = a == b
232fromOptional
232fromOptional
233− :: (Known (Sing s))
233+ :: SingI s
234 => Sing ('SchemaOptional s)
234 => Sing ('SchemaOptional s)
235 -> J.Value
235 -> J.Value
236 -> Parser (Maybe (JsonRepr s))
236 -> Parser (Maybe (JsonRepr s))
237fromOptional _ = parseJSON
237fromOptional _ = parseJSON
239−instance Known (Sing schema) => J.FromJSON (JsonRepr schema) where
239+instance SingI schema => J.FromJSON (JsonRepr schema) where
240− parseJSON value = case known :: Sing schema of
240+ parseJSON value = case sing :: Sing schema of
241 SSchemaText _ -> withText "String" (pure . ReprText) value
241 SSchemaText _ -> withText "String" (pure . ReprText) value
242 SSchemaNumber _ -> withScientific "Number" (pure . ReprNumber) value
242 SSchemaNumber _ -> withScientific "Number" (pure . ReprNumber) value
243 SSchemaNull -> case value of
243 SSchemaNull -> case value of