Qcert.CAMP.Typing.TCAMP


Section TCAMP.



Auxiliary lemmas
Auxiliary definitions and lemmas for type environments
Typing for CAMP

  Context {m:basic_model}.

  Reserved Notation "Γ |= p ; a ~> b" (at level 90).

Typing rules for CAMP Patterns

  Section t.
    Context (constants:tbindings).
  Inductive pat_type :
    tbindings pat rtype rtype Prop :=
    | PTconst Γ τ} d :
        data_type (normalize_data brand_relation_brands d) τ
        Γ |= pconst d ; τ ~> τ
    | PTunop {Γ τ τ τ u p} :
        Γ |= p ; τ ~> τ
        unaryOp_type u τ τ
        Γ |= punop u p ; τ ~> τ
    | PTbinop {Γ τ τ₂₁ τ₂₂ τ b p₁ p₂} :
        Γ |= p₁ ; τ ~> τ₂₁
        Γ |= p₂ ; τ ~> τ₂₂
        binOp_type b τ₂₁ τ₂₂ τ
        Γ |= pbinop b p₁ p₂ ; τ ~> τ
    | PTmap {Γ τ τ p} :
        Γ |= p ; τ ~> τ
                 Γ |= pmap p ; Coll τ ~> Coll τ

    | PTassert {Γ τ p} pf :
        Γ |= p ; τ ~> Bool
        Γ |= passert p ; τ ~> Rec Closed nil pf
    | PTorElse {Γ τ τ p₁ p₂} :
        Γ |= p₁ ; τ ~> τ
        Γ |= p₂ ; τ ~> τ
        Γ |= porElse p₁ p₂ ; τ ~> τ
    | PTit Γ τ : Γ |= pit ; τ ~> τ
    | PTletIt {Γ τ τ τ p₁ p₂} :
        Γ |= p₁ ; τ ~> τ
        Γ |= p₂ ; τ ~> τ
        Γ |= pletIt p₁ p₂ ; τ ~> τ
    | PTgetconstant {Γ} τ s τout:
        tdot constants s = Some τout
        Γ |= pgetconstant s; τ ~> τout
    | PTenv {Γ} τ pf :
        Γ |= penv ; τ ~> Rec Closed Γ pf
    | PTletEnv {Γ τ τ p₁ p₂} Γ' pf Γ'' :
        Γ |= p₁ ; τ ~> Rec Closed Γ' pf
        Some Γ'' = merge_bindings Γ Γ'
        Γ'' |= p₂ ; τ ~> τ
        Γ |= pletEnv p₁ p₂ ; τ ~> τ
    | PTLeft Γ τl τr :
        Γ |= pleft; (Either τl τr) ~> τl
    | PTRight Γ τl τr :
        Γ |= pright; (Either τl τr) ~> τr
       where "g |= p ; a ~> b" := (pat_type g p a b).

  End t.

Auxiliary lemmas for the type soudness results

  Lemma data_type_drec_nil pf :
    data_type (drec nil) (Rec Closed nil pf).



  Lemma concat_bindings_type {env₁ env₂ Γ₁ Γ₂} :
    bindings_type env₁ Γ₁
    bindings_type env₂ Γ₂
    bindings_type (env₁ ++ env₂)
                         (Γ₁ ++ Γ₂).

  Lemma insertion_sort_insert_bindings_type {env Γ d r} s :
     bindings_type env Γ
     data_type d r
     bindings_type
     (RSort.insertion_sort_insert rec_field_lt_dec
        (s, d) env)
     (RSort.insertion_sort_insert rec_field_lt_dec
        (s, r) Γ).

  Lemma rec_sort_bindings_type {env Γ} :
    bindings_type env Γ
    bindings_type (rec_sort env)
                         (rec_sort Γ).

  Lemma rec_concat_sort_bindings_type {env₁ env₂ Γ₁ Γ₂} :
    bindings_type env₁ Γ₁
    bindings_type env₂ Γ₂
    bindings_type (rec_concat_sort env₁ env₂)
                         (rec_concat_sort Γ₁ Γ₂).

  Lemma merge_bindings_type {env₁ env₂ env₃ Γ₁ Γ₂ Γ₃} :
        bindings_type env₁ Γ₁
        bindings_type env₂ Γ₂
        Some env₃ = merge_bindings env₁ env₂
        Some Γ₃ = merge_bindings Γ₁ Γ₂
        bindings_type env₃ Γ₃.

Main type soudness lemma

  Notation "[ c & g ] |= p ; a ~> b" := (pat_type c g p a b) (at level 90).

  Theorem typed_pat_success_or_recoverable {c} {τc}
          {Γ τin τout} {p:pat} {env} {d} :
    bindings_type c τc
     bindings_type env Γ
     ([τc & Γ] |= p ; τin ~> τout)
     (data_type d τin)
        ( x, interp brand_relation_brands c p env d = Success x (data_type x τout))
         (interp brand_relation_brands c p env d = RecoverableError).


Additional lemma used in the correctness for typed translation from NNRC to CAMP
  Lemma pat_type_tenv_recc Γ p τ τ} :
    NoDup (domain Γ)
    [τc & Γ] |= p; τ ~> τ
    [τc & rec_sort Γ] |= p; τ ~> τ.

  Lemma pat_type_const_sort_fc Γ p τ τ} :
    [rec_sort τc & Γ] |= p; τ ~> τ
    [τc & Γ] |= p; τ ~> τ.

  Lemma pat_type_const_sort_bc Γ p τ τ} :
    [τc & Γ] |= p; τ ~> τ
    [rec_sort τc & Γ] |= p; τ ~> τ.

  Lemma pat_type_const_sortc Γ p τ τ} :
    [rec_sort τc & Γ] |= p; τ ~> τ
    [τc & Γ] |= p; τ ~> τ.

End TCAMP.

Notation "[ c & g ] |= p ; a ~> b" := (pat_type c g p a b) (at level 90) : rule_scope.