Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sgdt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gradual-typing
sgdt
Commits
f3f8a389
Commit
f3f8a389
authored
1 year ago
by
Eric Giovannini
Browse files
Options
Downloads
Patches
Plain Diff
more work on abstract categorical model
parent
cf86400a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
paper-new/categorical-model.tex
+284
-16
284 additions, 16 deletions
paper-new/categorical-model.tex
paper-new/defs.tex
+4
-1
4 additions, 1 deletion
paper-new/defs.tex
with
288 additions
and
17 deletions
paper-new/categorical-model.tex
+
284
−
16
View file @
f3f8a389
...
...
@@ -38,10 +38,26 @@ categories}. Since reflexive graphs form a topos we can get at this by
interpreting the above definition
\emph
{
internally
}
to the topos of
reflexive graphs. Essentially what this means is that everything above
has a ``vertex'' component and an ``edge'' component, so we get a
cartesian category
$
\mathcal
V
_
v
$
which we think of as the value types
and pure functions but we also get a cartesian category
$
\mathcal
V
_
e
$
cartesian category
$
\mathcal
V
_
f
$
which we think of as the value types
and pure functions but we also get a cartesian category
$
\mathcal
V
_
{
sq
}
$
which we think of as the ``value edges'' and ``squares''.
More formally, for the values, we have
\begin{enumerate}
\item
Cartesian categories
$
\mathcal
V
_
f
$
and
$
\mathcal
V
_
e
$
with the same set of objects,
namely, the value types.
The morphisms of
$
\mathcal
V
_
f
$
will be called
\emph
{
(pure) functions
}
, and the
morphisms of
$
\mathcal
V
_
e
$
will be called
\emph
{
edges
}
or
\emph
{
relations
}
.
\item
A cartesian category
$
\mathcal
V
_{
sq
}$
whose objects are the morphisms of
$
\mathcal
V
_
e
$
and whose morphisms are
\emph
{
commuting squares
}
.
\item
Functors
$
s, t :
\mathcal
V
_{
sq
}
\to
\mathcal
V
_
f
$
and
$
i :
\mathcal
V
_
f
\to
\mathcal
V
_{
sq
}$
.
\end{enumerate}
Likewise, we have an analogous definition for computations.
We will work in ``locally thin'' models where there is at most one
square with a given boundary.
...
...
@@ -50,30 +66,282 @@ with reflexive graph models we also have access to new notions of
universal property that relate the ``function'' morphisms to the
``edges''.
Let
$
f :
\mathcal
V
_
v
(
A
_
i, A
_
o
)
$
and
$
R :
\mathcal
V
_
e
(
A
_
o,A'
)
$
then a
\emph
{
left restriction
}
of
$
R
$
along
$
f
$
consists of
\begin{enumerate}
\item
$
R' :
\mathcal
V
_
e
(
A
_
i,A'
)
$
\item
$
S
\Rightarrow
_{
g,h
}
R'
$
naturally isomorphic to
$
S
\Rightarrow
_{
fg,h
}
R
$
\end{enumerate}
In relational semantics,
$
R
(
a
_
o,a'
)
$
is a relation and the left
restriction along
$
f
$
is the relation
$
R
(
f
(
a
_
i
)
, a'
)
$
.
In particular, let
$
c
\in
\mathcal
V
_
e
(
A, A'
)
$
and
$
d
\in
\mathcal
V
_
e
(
A',A''
)
$
,
and let
$
f
\in
\mathcal
V
_
f
(
A, A'
)
$
and
$
g
\in
\mathcal
V
_
f
(
A', A''
)
$
.
We say that the pair
$
(
c,d
)
$
is
\emph
{
left-representable by
}
$
(
f, g
)
$
if the following two squares commute:
\begin{center}
\begin{tabular}
{
m
{
14em
}
m
{
14em
}
}
% UpL
\begin{tikzcd}
[ampersand replacement=
\&
]
A
\&
{
A'
}
\&
{
A''
}
\\
{
A'
}
\&\&
{
A''
}
\arrow
["f"', from=1-1, to=2-1]
%
\arrow
[from=1-3, to=2-3, Rightarrow, no head]
%
\arrow
["c", "\shortmid"{marking}, no head, from=1-1, to=1-2]
\arrow
["d", "\shortmid"{marking}, no head, from=1-2, to=1-3]
%
\arrow
["d"', "\shortmid"{marking}, no head, from=2-1, to=2-3]
\end{tikzcd}
&
% UpR
\begin{tikzcd}
[ampersand replacement=
\&
]
A
\&\&
{
A'
}
\\
{
A
}
\&
{
A'
}
\&
{
A''
}
\arrow
[from=1-1, to=2-1, Rightarrow, no head]
%
\arrow
["g", from=1-3, to=2-3]
%
\arrow
["c", "\shortmid"{marking}, no head, from=1-1, to=1-3]
%
\arrow
["c"', "\shortmid"{marking}, no head, from=2-1, to=2-2]
\arrow
["d"', "\shortmid"{marking}, no head, from=2-2, to=2-3]
\end{tikzcd}
\end{tabular}
\end{center}
Then we can formulate our value edges as follows:
Dually, let
$
c
\in
\mathcal
E
_
e
(
B, B'
)
$
and
$
d
\in
\mathcal
E
_
e
(
B', B''
)
$
,
and let
$
f
\in
\mathcal
E
_
f
(
B'', B'
)
$
and
$
g
\in
\mathcal
E
_
f
(
B', B
)
$
.
We say the pair
$
(
c,d
)
$
is
\emph
{
right-representable by
}
$
(
f,g
)
$
if the
following two squares commute:
\begin{center}
\begin{tabular}
{
m
{
14em
}
m
{
14em
}
}
% DnR
\begin{tikzcd}
[ampersand replacement=
\&
]
{
B
}
\&
{
B'
}
\&
{
B''
}
\\
{
B
}
\&\&
{
B'
}
\arrow
[from=1-1, to=2-1, Rightarrow, no head]
%
\arrow
["f", from=1-3, to=2-3]
%
\arrow
["c", "\shortmid"{marking}, no head, from=1-1, to=1-2]
\arrow
["d", "\shortmid"{marking}, no head, from=1-2, to=1-3]
%
\arrow
["c"', from=2-1, to=2-3, no head]
\end{tikzcd}
&
% DnL
\begin{tikzcd}
[ampersand replacement=
\&
]
{
B'
}
\&\&
{
B''
}
\\
{
B
}
\&
{
B'
}
\&
{
B''
}
\arrow
["g"', from=1-1, to=2-1]
%
\arrow
[from=1-3, to=2-3, Rightarrow, no head]
%
\arrow
["d", from=1-1, to=1-3, no head]
%
\arrow
["c"', "\shortmid"{marking}, no head, from=2-1, to=2-2]
\arrow
["d"', "\shortmid"{marking}, no head, from=2-2, to=2-3]
\end{tikzcd}
\end{tabular}
\end{center}
Then we formulate the relationship between value edges and functions as follows:
\begin{enumerate}
\item
We have a thin subcategory
$
\mathcal
V
_
u
$
of
$
\mathcal
V
_
v
$
, of ``upcasts''
\item
$
\mathcal
V
$
has all left restrictions of edges along upcasts
\item
There is a functor
$
\upf
:
\mathcal
V
_
e
\to
\mathcal
V
_
f
$
that is the
identity on objects, such that
$
\upf
_
*(
\mathcal
V
_
e
)
$
, the essential image of
$
\mathcal
V
_
e
$
under
$
\upf
$
, is thin.
The objects of
$
\upf
_
*(
\mathcal
V
_
e
)
$
are the objects of
$
\mathcal
V
_
f
$
, and
the hom-set
$
\upf
_
*(
\mathcal
V
_
e
)(
A, A'
)
=
\{
f
\in
\mathcal
V
_
f
(
A,A'
)
\mid
\exists
R
\in
\mathcal
V
_
e
(
A,A'
)
.
\upf
(
R
)
=
f
\}
$
.
\item
Every pair of morphisms
$
(
c,d
)
\in
\mathcal
V
_
e
(
A, A'
)
\times
\mathcal
V
_
e
(
A', A''
)
$
is
left-representable by
$
(
\upf
(
c
)
,
\upf
(
d
))
$
.
\end{enumerate}
And o
u
r computation
edges as follow
s:
And
likewise f
or computations:
\begin{enumerate}
\item
We have a thin subcategory
$
\mathcal
E
_
d
$
of
$
\mathcal
E
_
v
$
of ``downcasts''
\item
$
\mathcal
E
$
has all right restrictions of edges along downcasts
\item
There is a functor
$
\dnf
:
\mathcal
E
_
e
^{
op
}
\to
\mathcal
V
_
f
$
that is
the identity on objects, such that the essential image of
$
\mathcal
E
_
e
$
under
$
\dnf
$
is thin.
\item
Every pair of morphisms
$
(
c,d
)
\in
\mathcal
E
_
e
(
B, B'
)
\times
\mathcal
E
_
e
(
B',B''
)
$
is right-representable by
$
(
\dnf
(
d
)
,
\dnf
(
c
))
$
.
\end{enumerate}
We also require that the category
$
\mathcal
V
_
e
$
of relations is thin ``up to an
identity square'', i.e., for any
$
R, R'
\in
\mathcal
V
_
e
(
A, A'
)
$
we have that the
following square commutes:
\[
\begin
{
tikzcd
}
[
ampersand replacement
=
\&
]
A
\&
{
A'
}
\\
A
\&
{
A'
}
\arrow
[
from
=
1
-
1
, to
=
2
-
1
, Rightarrow, no head
]
\arrow
[
from
=
1
-
2
, to
=
2
-
2
, Rightarrow, no head
]
\arrow
[
"R", "
\shortmid
"
{
marking
}
, no head, from
=
1
-
1
, to
=
1
-
2
]
\arrow
[
"R'"', "
\shortmid
"
{
marking
}
, no head, from
=
2
-
1
, to
=
2
-
2
]
\end
{
tikzcd
}\]
\textbf
{
TODO: do we still need this?
}
We also want something like
\[
F
_
c :
\mathcal
V
_
u
^{
op
}
\to
\mathcal
E
_
d
\]
\[
U
_
c :
\mathcal
E
_
d
^{
op
}
\to
\mathcal
V
_
u
\]
which ensures that if
$
R
$
is a value edge equivalent to
$
A
(
u,
-)
$
then
\[
F
(
R
)
=
F
(
A
(
u,
-))
=
(
F A
)(-
,F u
)
\]
\subsection
{
Intensional Model
}
An intensional model of gradual typing is defined similarly to an extensional model,
but unlike in the extensional model, here we work internally to the category of
categories, giving us a double category.
In particular, as before, we have cartesian categories
$
\mathcal
V
_
f
$
,
$
\mathcal
V
_
e
$
, and
$
\mathcal
V
_{
sq
}$
, in addition to
$
\mathcal
E
_
f
$
,
$
\mathcal
E
_
e
$
, and
$
\mathcal
E
_{
sq
}$
.
But we now have horizontal composition of squares as well.
Working intensionally means we need to take into consideration the steps
taken by terms. One consequence of this is that the squares in the representable
properties must now involve a notion of ``delay" or ``perturbation'' in order to
keep the function morphisms on each side in lock-step. Intuitively, the perturbations
have no effect other than to cause the function to which they are applied to ``wait''
in a specific manner.
We formalize this notion by requiring that for each object
$
A :
\mathcal
V
_
v
$
,
there is a monoid of
\emph
{
perturbations
}
$
P
^
V
_
A
$
and a monoid homomorphism
$
\ptb
^
V
_
A : P
^
V
_
A
\to
\mathcal
V
_
v
(
A,A
)
$
.
Similarly, for each
$
B :
\mathcal
E
_
v
$
there is a monoid
$
P
^
C
_
B
$
and a
homomorphism
$
\ptb
^
C
_
B : P
^
C
_
B
\to
\mathcal
E
_
v
(
B,B
)
$
.
If
$
\delta
\in
P
^
V
_
A
$
, we will sometimes omit the homomorphism
$
\ptb
^
V
_
A
$
and simply write
$
\delta
$
to refer to the morphism
$
\ptb
^
V
_
A
(
\delta
)
\in
\mathcal
V
_
v
(
A,A
)
$
, and likewise
for computation perturbations. The context will make clear whether we are referring
to an element of the perturbation monoid or the corresponding morphism.
The perturbations must satisfy a property that we call the ``push-pull'' property,
which is formulated as follows. Let
$
c
\in
\mathcal
V
_
e
(
A, A'
)
$
.
Given a perturbation
$
\delta
\in
P
^
V
_
A
$
, there is a corresponding perturbation
$
\push
_
c
(
\delta
)
\in
P
^
V
_{
A'
}$
.
% making the following square commute:
%
Likewise, given
$
\delta
'
\in
P
^
V
_{
A'
}$
there is a perturbation
$
\pull
_
c
(
\delta
'
)
\in
P
^
V
_
A
$
.
% making the following square commute:
Moreover, the following squares commute:
\begin{center}
\begin{tabular}
{
m
{
9em
}
m
{
9em
}
}
\begin{tikzcd}
[ampersand replacement=
\&
]
A
\&
{
A'
}
\\
A
\&
{
A'
}
\arrow
["\delta"', from=1-1, to=2-1]
\arrow
["{\push_c(\delta)}", from=1-2, to=2-2]
\arrow
["c", "\shortmid"{marking}, no head, from=1-1, to=1-2]
\arrow
["c"', "\shortmid"{marking}, no head, from=2-1, to=2-2]
\end{tikzcd}
&
\begin{tikzcd}
[ampersand replacement=
\&
]
A
\&
{
A'
}
\\
A
\&
{
A'
}
\arrow
["{\pull_c(\delta')}"', from=1-1, to=2-1]
\arrow
["{\delta'}", from=1-2, to=2-2]
\arrow
["c", "\shortmid"{marking}, no head, from=1-1, to=1-2]
\arrow
["c"', "\shortmid"{marking}, no head, from=2-1, to=2-2]
\end{tikzcd}
\end{tabular}
\end{center}
The analogous property should also hold for computation relations and perturbations.
A second consequence of working intensionally is that we need a way to specify
that two morphisms are the same ``up to delay'', i.e., they differ only in that
one may wait more than the other.
%
To this end, for any pair of objects
$
A
$
and
$
A'
$
, in
$
\mathcal
V
_
f
$
, we require that
there is a reflexive, symmetric relation
$
\bisim
_{
A,A'
}$
on the hom-set
$
\mathcal
V
_
f
(
A, A'
)
$
,
called the
\emph
{
weak bisimilarity
}
relation.
Similarly for the computation category: there is a relation
$
\bisim
_{
B,B'
}$
defined on each hom-set
$
\mathcal
E
_
v
(
B, B'
)
$
.
We require that all perturbations be weakly bisimilar to the identity function,
capturing the notion that they have no effect other than to delay.
The weak bisimilarity relation should respect composition:
if
$
f
\bisim
_{
A,A'
}
f'
$
and
$
g
\bisim
_{
A',A''
}
g'
$
, then
$
g
\circ
f
\bisim
_{
A,A''
}
g'
\circ
f'
$
, and likewise for computations.
% We similarly have thin subcategories $\mathcal V_u$ and $\mathcal E_d$ of
% upcasts and downcasts. The relation between function morphisms and edges
% is as follows.
As is the case in the extensional model, there is a relationship between
function morphisms and relation morphisms, but as mentioned above, now there
are perturbations involved in order to keep both morphisms in lock-step.
The precise definitions are as follows.
Let
$
c
\in
\mathcal
V
_
e
(
A, A'
)
$
. We say that
$
c
$
is
\emph
{
quasi-left-representable by
}
$
f
\in
\mathcal
V
_
f
(
A, A'
)
$
if there exist perturbations
$
\delta
_
c
^{
l,e
}
\in
P
^
V
_
A
$
and
$
\delta
_
c
^{
r,e
}
\in
P
^
V
_{
A'
}$
such that the following squares commute:
\begin{center}
\begin{tabular}
{
m
{
7em
}
m
{
7em
}
}
% UpL
\begin{tikzcd}
[ampersand replacement=
\&
]
A
\&
{
A'
}
\\
{
A'
}
\&
{
A'
}
\arrow
["f"', from=1-1, to=2-1]
\arrow
["\delta_c^{r,e}", from=1-2, to=2-2]
\arrow
["c", "\shortmid"{marking}, no head, from=1-1, to=1-2]
\arrow
[from=2-1, to=2-2, Rightarrow, no head]
\end{tikzcd}
&
% UpR
\begin{tikzcd}
[ampersand replacement=
\&
]
A
\&
{
A
}
\\
{
A
}
\&
{
A'
}
\arrow
["\delta_c^{l,e}"', from=1-1, to=2-1]
\arrow
["f", from=1-2, to=2-2]
\arrow
[from=1-1, to=1-2, Rightarrow, no head]
\arrow
["c"', "\shortmid"{marking}, no head, from=2-1, to=2-2]
\end{tikzcd}
\end{tabular}
\end{center}
Similarly, let
$
d
\in
\mathcal
E
_
e
(
B, B'
)
$
. We say that
$
d
$
is
\emph
{
quasi-right-representable by
}
$
f
\in
\mathcal
E
_
f
(
B', B
)
$
if there exist perturbations
$
\delta
_
d
^{
l,p
}
\in
P
^
C
_
B
$
and
$
\delta
_
d
^{
r,p
}
\in
P
^
C
{
B'
}$
such that the following squares commute:
\begin{center}
\begin{tabular}
{
m
{
7em
}
m
{
7em
}
}
% DnR
\begin{tikzcd}
[ampersand replacement=
\&
]
{
B
}
\&
{
B'
}
\\
{
B
}
\&
{
B
}
\arrow
["\delta_d^{l,p}"', from=1-1, to=2-1]
\arrow
["g", from=1-2, to=2-2]
\arrow
["R", "\shortmid"{marking}, no head, from=1-1, to=1-2]
\arrow
[from=2-1, to=2-2, Rightarrow, no head]
\end{tikzcd}
&
% DnL
\begin{tikzcd}
[ampersand replacement=
\&
]
{
B'
}
\&
{
B'
}
\\
{
B
}
\&
{
B'
}
\arrow
["g"', from=1-1, to=2-1]
\arrow
["\delta_d^{r,p}", from=1-2, to=2-2]
\arrow
[from=1-1, to=1-2, Rightarrow, no head]
\arrow
["R"', "\shortmid"{marking}, no head, from=2-1, to=2-2]
\end{tikzcd}
\end{tabular}
\end{center}
Besides the perturbations, one other difference between the extensional
and intensional versions of the representability axioms is that in the
extensional setting, the rules build in the notion of composition, whereas
their intensional counterparts do not.
In the extensional setting, we do not have horizontal composition of squares, which
is required to derive the versions of the rules that build in composition
from the versions that do not.
In the intensional setting, we do have horizontal composition of squares,
so we can take the simpler versions as primitive and derive the ones
involving composition (though we must be careful about the perturbations
when doing so!).
\subsection
{
Constructing an Extensional Model from an Intensional Model
}
This diff is collapsed.
Click to expand it.
paper-new/defs.tex
+
4
−
1
View file @
f3f8a389
...
...
@@ -66,7 +66,7 @@
\newcommand
{
\hasty
}
[3]
{{
#1
}
\vdash
{
#2
}
\colon
{
#3
}}
\newcommand
{
\vhasty
}
[3]
{{
#1
}
\vdash
^
v
{
#2
}
\colon
{
#3
}}
\newcommand
{
\phasty
}
[3]
{{
#1
}
\vdash
^
p
{
#2
}
\colon
{
#3
}}
\newcommand
{
\phasty
}
[3]
{{
#1
}
\vdash
^
c
{
#2
}
\colon
{
#3
}}
\newcommand
{
\etmprec
}
[4]
{{
#1
}
\vdash
{
#2
}
\ltdyn
_
e
{
#3
}
\colon
{
#4
}}
\newcommand
{
\itmprec
}
[4]
{{
#1
}
\vdash
{
#2
}
\ltdyn
_
i
{
#3
}
\colon
{
#4
}}
\newcommand
{
\etmequidyn
}
[4]
{{
#1
}
\vdash
{
#2
}
\equidyn
_
e
{
#3
}
\colon
{
#4
}}
...
...
@@ -154,3 +154,6 @@
\newcommand
{
\ptb
}{
\text
{
ptb
}}
\newcommand
{
\push
}{
\text
{
push
}}
\newcommand
{
\pull
}{
\text
{
pull
}}
\newcommand
{
\upf
}{
\text
{
up
}}
\newcommand
{
\dnf
}{
\text
{
dn
}}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment