brandonchinn178 / aeson-schemas

Easily consume JSON data on-demand with type-safety
http://hackage.haskell.org/package/aeson-schemas
BSD 3-Clause "New" or "Revised" License
52 stars 1 forks source link

Add constraint for schema subsets #2

Open brandon-leapyear opened 5 years ago

brandon-leapyear commented 5 years ago

It would be nice to have a constraint like SchemaHas base schema that constrains that schema contains at least base. Don't know if this is even possible, requires research.

For example,

type UserSchema = [schema| { userId: Int } |]
type BossSchema = [schema| { group: Text, #UserSchema } |]
type WorkerSchema = [schema| { projects: List Text, #UserSchema } |]

-- would work when passed `Object BossSchema` or `Object WorkerSchema`
getUserId :: SchemaHas UserSchema schema => Object schema -> Int
getUserId = [get| .userId |]