#NAME dk_obj.
(;
Copyright Raphaël Cauderlier (2014)
This software is a computer program whose purpose is to translate object-oriented program written in the simply-typed ς-calculus from Abadi and Cardelli to Dedukti and Coq.
This software is governed by the CeCILL-B license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-B
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided
only with a limited warranty and the software's author, the holder of
the economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards
their requirements in conditions enabling the security of their
systems and/or data to be ensured and, more generally, to use and
operate it in the same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-B license and that you accept its terms.
;)
(; Labels ;)
def label := string.
(; Object types ;)
def type := dk_type.type. (; type := list (label * type) ;)
def Ot_nil := dk_type.tnil.
def Ot_cons := dk_type.tcons.
def Ot_st := dk_type.st.
def Ot_domain_subtype := dk_type.domain_subtype.
def pos := dk_type.pos.
(; Expressions, methods and objects ;)
PreObj : type -> type -> Type.
def Expr : type -> Type.
[A] Expr A --> PreObj A A.
Po_nil : A : type ->
PreObj A Ot_nil.
Po_cons : A : type ->
D : type ->
l : label ->
B : type ->
(Expr A -> Expr B) ->
PreObj A D ->
PreObj A (Ot_cons l B D).
def preselect : A : type ->
D : type ->
o : PreObj A D ->
l : label ->
B : type ->
pos l B D ->
Expr A ->
Expr B.
[m] preselect _ _ (Po_cons _ _ _ _ m _) _ _ (dk_type.at_head _ _ _) --> m.
[A,D,l,l2,o,H,Htl]
preselect
_
_
(Po_cons A D _ _ _ o)
l
H
(dk_type.in_tail _ _ _ _ _ Htl)
-->
preselect A D o l H Htl.
def preupdate : A : type ->
D : type ->
o : PreObj A D ->
l : label ->
B : type ->
H : pos l B D ->
(Expr A -> Expr B) ->
PreObj A D.
[A,D,l,B,o,m2]
preupdate
_
_
(Po_cons A D l B _ o)
_
_
(dk_type.at_head _ _ _)
m2
-->
Po_cons A D l B m2 o
[A,D,l,l2,B,m1,m2,o,p,C]
preupdate
_
_
(Po_cons A D l2 B m1 o)
l
C
(dk_type.in_tail _ _ _ _ _ p)
m2
-->
Po_cons A D l2 B m1 (preupdate A D o l C p m2).
def obj_select : A : type ->
eA : Expr A ->
l : label ->
B : type ->
pos l B A ->
Expr B.
[A,o,l,B,p]
obj_select A o l B p
-->
preselect
A
A
o
l
B
p
o.
(; The definitions of select and update
are limited to objects so that selection
and updating other expressions is still definable. ;)
def select : A : type ->
eA : Expr A ->
l : label ->
B : type ->
pos l B A ->
Expr B.
[A,D,l,B,m,po]
select _ (Po_cons A D l B m po)
-->
obj_select A (Po_cons A D l B m po).
def obj_update : A : type ->
eA : Expr A ->
l : label ->
B : type ->
pos l B A ->
(Expr A -> Expr B) ->
Expr A.
[A] obj_update A --> preupdate A A.
def update : A : type ->
eA : Expr A ->
l : label ->
B : type ->
pos l B A ->
(Expr A -> Expr B) ->
Expr A.
[A,D,l,B,m,po]
update _ (Po_cons A D l B m po)
-->
obj_update A (Po_cons A D l B m po).
def preinit : A : type ->
C : type ->
(l : label -> B : type -> pos l B C -> pos l B A) ->
PreObj A C.
[A] preinit A dk_type.tnil _ --> Po_nil A
[A,l,B,C,Hsub]
preinit A (dk_type.tcons l B C) Hsub
-->
Po_cons
A
C
l
B
(self : Expr A => select A self l B (Hsub l B (dk_type.at_head l B C)))
(preinit A C
(l2 : label => B' : type => p : pos l2 B' C =>
Hsub l2 B' (dk_type.in_tail l2 B' l B C p))).
def init : A : type -> Expr A.
[A] init A --> preinit A A (l : label => B : type => p : pos l B A => p).
(; Subtyping ;)
def coerce : A : type ->
B : type ->
Ot_st A B ->
Expr A ->
Expr B.
[A,B,st,a]
select _ (coerce A B st a)
-->
(l : label => C : type => p : pos l C B =>
select A a l C (dk_type.domain_subtype A B st l C p)).
[A,B,st,a]
update _ (coerce A B st a)
-->
(l : label => C : type => p : pos l C B => m : (Expr B -> Expr C) =>
coerce A B st
(update A a l C (dk_type.domain_subtype A B st l C p)
(self : Expr A =>
m (coerce A B st self)))).
[A,B,C,stAB,stBC,a]
coerce B C stBC (coerce A _ stAB a)
-->
coerce A C (dk_type.st_trans A B C stAB stBC) a.