Module Qcert.Data.ModelTyping.TDData
Require
Import
String
.
Require
Import
List
.
Require
Import
Sumbool
.
Require
Import
Arith
.
Require
Import
Bool
.
Require
Import
Morphisms
.
Require
Import
Basics
.
Require
Import
BrandRelation
.
Require
Import
Utils
.
Require
Import
Types
.
Require
Import
ForeignData
.
Require
Import
DataModel
.
Require
Import
ForeignDataTyping
.
Require
Import
TData
.
Section
TDData
.
Context
{
fdata
:
foreign_data
}.
Context
{
ftype
:
foreign_type
}.
Context
{
fdtyping
:
foreign_data_typing
}.
Context
{
m
:
brand_model
}.
Inductive
ddata_type
:
ddata
->
drtype
->
Prop
:=
|
dtlocal
d
τ :
data_type
d
τ ->
ddata_type
(
Dlocal
d
) (
Tlocal
τ)
|
dtdistr
dl
τ :
Forall
(
fun
d
=>
data_type
d
τ)
dl
->
ddata_type
(
Ddistr
dl
) (
Tdistr
τ).
Lemma
ddata_dtype_normalized
d
d
τ :
ddata_type
d
d
τ ->
ddata_normalized
brand_relation_brands
d
.
Proof.
intros
.
destruct
d
;
simpl
in
*.
-
inversion
H
.
subst
.
constructor
.
apply
(
data_type_normalized
d
τ
H1
).
-
inversion
H
.
subst
.
constructor
.
rewrite
Forall_forall
in
*;
intros
.
specialize
(
H1
x
H0
).
apply
(
data_type_normalized
x
τ
H1
).
Qed.
Definition
drtype_sub
(
d
τ₁
d
τ₂:
drtype
) :
Prop
:=
match
d
τ₁,
d
τ₂
with
|
Tlocal
τ₁,
Tlocal
τ₂ => τ₁ ≤ τ₂
|
Tdistr
τ₁,
Tdistr
τ₂ => τ₁ ≤ τ₂
|
_
,
_
=>
False
end
.
Global
Instance
drtype_sub_pre
:
PreOrder
drtype_sub
.
Proof.
constructor
;
red
;
intros
.
-
destruct
x
;
constructor
.
-
destruct
x
;
destruct
y
;
simpl
in
* ;
try
tauto
;
destruct
z
;
simpl
in
* ;
try
tauto
;
etransitivity
;
eauto
.
Qed.
Global
Instance
drtype_sub_part
:
PartialOrder
eq
drtype_sub
.
Proof.
intros
d
τ₁
d
τ₂.
split
;
intros
H
.
-
repeat
red
;
subst
;
intuition
.
-
repeat
red
in
H
;
intuition
.
unfold
flip
in
H1
.
destruct
d
τ₁;
destruct
d
τ₂
;
simpl
in
* ;
try
tauto
;
f_equal
;
apply
antisymmetry
;
auto
.
Qed.
Global
Instance
ddata_type_sub
:
Proper
(
eq
==>
drtype_sub
==>
impl
)
ddata_type
.
Proof.
unfold
Proper
,
respectful
,
impl
;
intros
d
d
' ?
d
τ₁
d
τ₂
sub
typ
;
subst
d
'.
destruct
d
;
destruct
d
τ₁
;
simpl
in
*;
invcs
typ
;
destruct
d
τ₂;
try
tauto
;
constructor
.
-
rewrite
sub
in
H1
;
trivial
.
-
rewrite
Forall_forall
in
*.
intros
d
ind
.
specialize
(
H1
_
ind
).
rewrite
sub
in
H1
.
trivial
.
Qed.
Lemma
drtype_sub_dec
(
d
τ₁
d
τ₂:
drtype
) :
{
drtype_sub
d
τ₁
d
τ₂} + {~
drtype_sub
d
τ₁
d
τ₂}.
Proof.
destruct
d
τ₁;
destruct
d
τ₂
;
simpl
.
-
apply
subtype_dec
.
-
right
;
tauto
.
-
right
;
tauto
.
-
apply
subtype_dec
.
Defined.
End
TDData
.