@@ -1,76 +0,0 @@
1−{-# LANGUAGE AllowAmbiguousTypes #-}
3−module Data.Schematic.Schema where
18−type family Repr (ty :: k1) :: k2 where
19− Repr JText = String -- because of matchRegex
20− Repr JNumber = Double
22−class Schema schema where
24− predicate :: Repr (Term ty) -> Bool
26−data Regexp (s :: Symbol) = Regexp
28−instance KnownSymbol reg => Schema (Regexp reg) subschema where
29− type Term (Regexp reg) subschema = Term ((), subschema)
30− predicate = isJust . matchRegex (mkRegex $ symbolVal (Proxy :: Proxy reg))
32−data LengthEqNat (n :: Nat)
33−data LengthGtNat (n :: Nat)
34−data LengthGeNat (n :: Nat)
35−data LengthLtNat (n :: Nat)
36−data LengthLeNat (n :: Nat)
38−instance KnownNat n => Schema (LengthEqNat n) subschema where
39− type Term (LengthEqNat n) s = Term s
40− predicate s = natVal (Proxy :: Proxy n) == fromIntegral (length s)
43−instance KnownNat n => Schema (LengthGtNat n) rest where
44− type Term (LengthGtNat n) = JNumber
45− predicate s = natVal (Proxy :: Proxy n) > fromIntegral (length s)
47−instance KnownNat n => Schema (LengthGeNat n) rest where
48− type Term (LengthGeNat n) = JNumber
49− predicate s = natVal (Proxy :: Proxy n) >= fromIntegral (length s)
51−instance KnownNat n => Schema (LengthLtNat n) rest where
52− type Term (LengthLtNat n) = JNumber
53− predicate s = natVal (Proxy :: Proxy n) < fromIntegral (length s)
55−instance KnownNat n => Schema (LengthLeNat n) rest where
56− type Term (LengthLeNat n) = JNumber
57− predicate s = natVal (Proxy :: Proxy n) <= fromIntegral (length s)
59−-- | Corresponds to [] or {} json values.
60−data EmptyObj = EmptyObj
62−data ConsObj (s :: Symbol) jsval = ConsObj
64−-- data Schema a where
65−-- (:*:) :: KnownSymbol label => label -> Schema l -> Schema r -> Schema a
66−-- (:%:) :: Schema c a => Schema a -> c a -> Schema a
69−data (s :: Symbol) :+: obj = (:+:) a b
76−schema = "foo" :%: (Regexp "foo") :*: Nil