Qcert.Backend.JSON


Section JSON.



  Context {fdata:foreign_data}.

  Inductive json : Set :=
  | jnil : json
  | jnumber : Z json
  | jbool : bool json
  | jstring : string json
  | jarray : list json json
  | jobject : list (string × json) json
  | jforeign : foreign_data_type json
  .


Induction principles used as backbone for inductive proofs on json
  Definition json_rect (P : json Type)
             (fnil : P jnil)
             (fnumber : n : Z, P (jnumber n))
             (fbool : b : bool, P (jbool b))
             (fstring : s : string, P (jstring s))
             (farray : c : list json, Forallt P c P (jarray c))
             (fobject : r : list (string × json), Forallt (fun abP (snd ab)) r P (jobject r))
             (fforeign: fd, P (jforeign fd))
    :=
      fix F (j : json) : P j :=
    match j as j0 return (P j0) with
      | jnilfnil
      | jnumber xfnumber x
      | jbool xfbool x
      | jstring xfstring x
      | jarray xfarray x ((fix F2 (c : list json) : Forallt P c :=
                            match c as c0 with
                              | nilForallt_nil _
                              | cons j c0 ⇒ @Forallt_cons _ P j c0 (F j) (F2 c0)
                            end) x)
      | jobject xfobject x ((fix F3 (r : list (string×json)) : Forallt (fun abP (snd ab)) r :=
                           match r as c0 with
                             | nilForallt_nil _
                             | cons sj c0 ⇒ @Forallt_cons _ (fun abP (snd ab)) sj c0 (F (snd sj)) (F3 c0)
                           end) x)
      | jforeign fdfforeign fd
    end.

  Definition json_ind (P : json Prop)
             (fnil : P jnil)
             (fnumber : n : Z, P (jnumber n))
             (fbool : b : bool, P (jbool b))
             (fstring : s : string, P (jstring s))
             (farray : c : list json, Forall P c P (jarray c))
             (fobject : r : list (string × json), Forall (fun abP (snd ab)) r P (jobject r))
             (fforeign: fd, P (jforeign fd))
    :=
      fix F (j : json) : P j :=
    match j as j0 return (P j0) with
      | jnilfnil
      | jnumber xfnumber x
      | jbool xfbool x
      | jstring xfstring x
      | jarray xfarray x ((fix F2 (c : list json) : Forall P c :=
                            match c with
                              | nilForall_nil _
                              | cons j c0 ⇒ @Forall_cons _ P j c0 (F j) (F2 c0)
                            end) x)
      | jobject xfobject x ((fix F3 (r : list (string×json)) : Forall (fun abP (snd ab)) r :=
                           match r with
                             | nilForall_nil _
                             | cons sj c0 ⇒ @Forall_cons _ (fun abP (snd ab)) sj c0 (F (snd sj)) (F3 c0)
                           end) x)
      | jforeign fdfforeign fd
    end.

  Definition json_rec (P:jsonSet) := json_rect P.

  Lemma jsonInd2 (P : json Prop)
        (f : P jnil)
        (f0 : n : Z, P (jnumber n))
        (fb : b : bool, P (jbool b))
        (f1 : s : string, P (jstring s))
        (f2 : c : list json, ( x, In x c P x) P (jarray c))
        (f3 : r : list (string × json), ( x y, In (x,y) r P y) P (jobject r))
        (fforeign : fd, P (jforeign fd)):
     d, P d.

End JSON.