SO
Size: a a a
SO
SO
SO
EG
EG
SG
GP
data PrimitiveKind
foreign import data Bool_Kind :: PrimitiveKind
foreign import data String_Kind :: PrimitiveKind
data Primitive :: PrimitiveKind -> Symbol -> Type
data Primitive k a =
SBool(SProxy a)
| SString(SProxy a)
getBool :: forall r r' l
. IsSymbol l
=> Cons l Boolean r' r
=> Primitive Bool_Kind l
-> { | r }
-> Boolean
getBool (SBool p) o = get p o
VK
ЗП
GP
ЗП
GP
GP
module type Field = {
type t
type r
type meta
let get: r => t
let set: (r, t) => r
}
type obj =
| Obj
type arr =
| Arr
type nullable =
| Nullable
type 't primitive =
| SInt: int primitive
| SFloat: float primitive
| SString: string primitive
| Sbool: bool primitive
type ('t,'r,_) t =
| Primitive: 't primitive* (module Field with type t = 't and type r = 'r)
-> ('t primitive,'r,'t) t
| SObject: ('s,'t,'k) t array*
(module Field with type t = 't and type r = 'r) -> (obj,'r,'t) t
| SArr: ('k,'r,'t) t* 't array*
(module Field with type t = 't array and type r = 'r) -> (arr,'r,'t array)
t
| SNull: ('k,'r,'t) t* 't option*
(module Field with type t = 't option and type r = 'r) ->
(nullable,'r,'t option) t
GP
GP
data Obj = Obj
data Arr = Arr
data Primitive a where
SInt :: Primitive Int
SString :: Primitive String
SBool :: Primitive Bool
data Schema k l where
SPrimitive :: Primitive k -> SProxy l -> Schema (Primitive k) l
SObject :: [Schema s l] -> SProxy l -> Schema Obj l
SObjectRoot :: [Schema s l] -> Schema Obj l
SArray :: Schema k l -> SProxy l -> Schema Arr l
type fullName = { name: String }
type user = {
age: Int
}
test = SObjectRoot [
SPrimitive SInt (SProxy :: SProxy "age"),
SObject [
SPrimitive SString (SProxy :: SProxy "name")
] (SProxy :: SProxy "fullName")
]
GP
data Lens a b = Lens { get :: a -> b
, set :: b -> a -> a
}
data SchemaKind a = Primitive a | Obj | Arr | Null
data Primitive a where
SInt :: Primitive Int
SString :: Primitive String
SBool :: Primitive Bool
SFloat :: Primitive Float
data SchemaListItem t = forall s k. SchemaListItem (Schema s t k)
data Schema t r t2 where
SPrimitive :: Primitive t -> Lens r t -> Schema ('Primitive t) r t
SObject ::[ SchemaListItem t ] -> Lens r t -> Schema 'Obj r t
SArray :: Schema k r t -> Lens r [t] -> Schema 'Arr r [t]
SNull :: Schema k r t -> Lens r (Maybe t) -> Schema 'Null r (Maybe t)
p
GP
data FullName = FullName { name :: String, surname :: String }
data User = User { fullName :: FullName, age :: Int, len :: Float }
SObject[
SchemaListItem (SPrimitive(SInt) ageLens),
SchemaListItem (SPrimitive(SFloat) lenLens),
SchemaListItem (SObject[..….] fullNameLens)
]
p
GP
handleObject :: Schema 'Obj r t -> …