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
fb5c8d73
Commit
fb5c8d73
authored
1 year ago
by
Eric Giovannini
Browse files
Options
Downloads
Patches
Plain Diff
check in semantics file before making changes
parent
3159ce55
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
paper-new/semantics.tex
+179
-31
179 additions, 31 deletions
paper-new/semantics.tex
with
179 additions
and
31 deletions
paper-new/semantics.tex
+
179
−
31
View file @
fb5c8d73
...
...
@@ -12,15 +12,15 @@ the construction of the monad and the dynamic type.
\section
{
Domain-Theoretic Constructions
}
\label
{
sec:domain-theory
}
In this section, we discuss the fundamental objects of the model into which we will embed
the
intensional
lambda calculus and inequational theory. It is important to remember that
the
step-sensitive
lambda calculus
$
\intlc
$
and inequational theory. It is important to remember that
the constructions in this section are entirely independent of the syntax described in the
previous section; the notions defined here exist in their own right as purely mathematical
constructs. In the next section, we will link the syntax and semantics via a
n
interpretation
constructs. In the next section, we will link the syntax and semantics via a
semantic
interpretation
function.
\subsection
{
The Lift Monad
}
When thinking about how to model intensional gradually-typed programs, we
must
consider
When thinking about how to model intensional gradually-typed programs, we
should
consider
their possible behaviors. On the one hand, we have
\emph
{
failure
}
: a program may fail
at run-time because of a type error. In addition to this, a program may ``think'',
i.e., take a step of computation. If a program thinks forever, then it never returns a value,
...
...
@@ -42,7 +42,7 @@ the \emph{lift monad}, as the following datatype:
\end{align*}
Unless otherwise mentioned, all constructs involving
$
\later
$
or
$
\fix
$
are understood to be with re
p
sect to a fixed clock
$
k
$
. So for the above, we really have for each
are understood to be with res
p
ect to a fixed clock
$
k
$
. So for the above, we really have for each
clock
$
k
$
a type
$
\li
^
k A
$
with respect to that clock.
Formally, the lift monad
$
\li
A
$
is defined as the solution to the guarded recursive type equation
...
...
@@ -56,7 +56,7 @@ Notice there is a computation $\fix \theta$ of type $\li A$. This represents a c
that thinks forever and never returns a value.
Since we claimed that
$
\li
A
$
is a monad, we need to define the monadic operations
and show that they repect the monadic laws. The return is just
$
\eta
$
, and extend
and show that they re
s
pect the monadic laws. The return is just
$
\eta
$
, and extend
is defined via by guarded recursion by cases on the input.
% It is instructive to give at least one example of a use of guarded recursion, so
% we show below how to define extend:
...
...
@@ -65,12 +65,17 @@ is defined via by guarded recursion by cases on the input.
%
Verifying that the monadic laws hold requires
\lob
-induction and is straightforward.
\begin{comment}
% Since this mentions the ordering on B, it should be introduced after introducing predomains.
The lift monad has the following universal property. Let
$
f
$
be a function from
$
A
$
to
$
B
$
,
where
$
B
$
is a
$
\later
$
-algebra, i.e., there is
$
\theta
_
B
\colon
\later
B
\to
B
$
.
Further suppose that
$
B
$
is also an ``error-algebra'', that is, an algebra of the
constant functor
$
1
\colon
\text
{
Type
}
\to
\text
{
Type
}$
mapping all types to Unit.
This latter statement amounts to saying that there is a map
$
\text
{
Unit
}
\to
B
$
, so
$
B
$
has a
distinguished ``error element"
$
\mho
_
B
\colon
B
$
.
Further suppose that
$
B
$
is also an ``error-algebra'', that is, there is an error element
$
\mho
_
B
$
such that
$
\mho
_
B
\le
_
B y
$
for all
$
y
\in
B
$
.
% Further suppose that $B$ is also an algebra of the
% constant functor $1 \colon \text{Type} \to \text{Type}$ mapping all types to Unit.
% This latter statement amounts to saying that there is a map $\text{Unit} \to B$, so $B$ has a
% distinguished ``error element" $\mho_B \colon B$ such that $\mho_B \le_B y$ for all $y \in B$.
Then there is a unique homomorphism of algebras
$
f'
\colon
\li
A
\to
B
$
such that
$
f'
\circ
\eta
=
f
$
. The function
$
f'
(
l
)
$
is defined via guarded fixpoint by cases on
$
l
$
.
...
...
@@ -79,40 +84,42 @@ In the $\theta(\tilde{l})$ case, we will return
\[
\theta
_
B
(
\lambda
t .
(
f'
_
t
\,
\tilde
{
l
}_
t
))
.
\]
Recalling that
$
f'
$
is a guaded fixpoint, it is available ``later'' and by
Recalling that
$
f'
$
is a gua
r
ded fixpoint, it is available ``later'' and by
applying the tick we get a function we can apply ``now''; for the argument,
we apply the tick to
$
\tilde
{
l
}$
to get a term of type
$
\li
A
$
.
\end{comment}
%\subsubsection{Model-Theoretic Description}
%We can describe the lift monad in the topos of trees model as follows.
\subsection
{
Predomains
}
\subsection
{
Predomains
}
\label
{
sec:predomains
}
The next important construction is that of a
\emph
{
predomain
}
. A predomain is intended to
model the notion of error ordering that we want terms to have. Thus, we define a predomain
$
A
$
as a partially-ordered set, which consists of a type which we denote
$
\ty
{
A
}$
and a reflexive,
transitive, and antisymmetric relation
$
\le
_
P
$
on
$
A
$
.
We define monotone functions between predomain as expected. Given predomains
$
A
$
and
$
B
$
, we write
$
f
\colon
A
_
i
\monto
A
_
o
$
to indicate that
$
f
$
is a monotone
function from
$
A
_
i
$
to
$
A
_
o
$
, i.e, for all
$
a
_
1
\le
_{
A
_
i
}
a
_
2
$
, we have
$
f
(
a
_
1
)
\le
_{
A
_
o
}
f
(
a
_
2
)
$
.
We also define an ordering on monotone functions as
$
f
\le
g
$
if for all
$
a
$
in
$
\ty
{
A
_
i
}$
, we have
$
f
(
a
)
\le
_{
A
_
o
}
g
(
a
)
$
.
For each type we want to represent, we define a predomain for the corresponding semantic
type. For instance, we define a predomain for natural numbers, a predomain for the
dynamic type, a predomain for functions, and a predomain for the lift monad. We
describe each of these below.
We define monotone functions between predomain as expected. Given predomains
$
A
$
and
$
B
$
, we write
$
f
\colon
A
\monto
B
$
to indicate that
$
f
$
is a monotone
function from
$
A
$
to
$
B
$
, i.e, for all
$
a
_
1
\le
_
A a
_
2
$
, we have
$
f
(
a
_
1
)
\le
_
B f
(
a
_
2
)
$
.
\begin{itemize}
\item
There is a predomain Nat for natural numbers, where the ordering is equality.
\item
There is a predomain
$
\
Nat
$
for natural numbers, where the ordering is equality.
\item
There is a predomain Dyn to represent the dynamic type. The underlying type
\item
There is a predomain
$
\
Dyn
$
to represent the dynamic type. The underlying type
for this predomain is defined by guarded fixpoint to be such that
$
\ty
{
\Dyn
}
\cong
\mathbb
{
N
}
\,
+
\,
\later
(
\ty
{
\Dyn
}
\monto
\ty
{
\Dyn
}
)
$
.
$
\ty
{
\Dyn
}
\cong
\mathbb
{
N
}
\,
+
\,
\later
(
\ty
{
\Dyn
}
\monto
\li
\ty
{
\Dyn
}
)
$
.
This definition is valid because the occurrences of Dyn are guarded by the
$
\later
$
.
The ordering is defined via guarded recursion by cases on the argument, using the
ordering on
$
\mathbb
{
N
}$
and the ordering on monotone functions described
below
.
ordering on
$
\mathbb
{
N
}$
and the ordering on monotone functions described
above
.
\item
For a predomain
$
A
$
, there is a predomain
$
\li
A
$
for the ``lift'' of
$
A
$
using the lift monad. We use the same notation for
$
\li
A
$
when
$
A
$
is a type
...
...
@@ -124,8 +131,10 @@ function from $A$ to $B$, i.e, for all $a_1 \le_A a_2$, we have $f(a_1) \le_B f(
\item
For predomains
$
A
_
i
$
and
$
A
_
o
$
, we form the predomain of monotone functions
from
$
A
_
i
$
to
$
A
_
o
$
, which we denote by
$
A
_
i
\To
A
_
o
$
.
The ordering is such that
$
f
$
is below
$
g
$
if for all
$
a
$
in
$
\ty
{
A
_
i
}$
, we have
$
f
(
a
)
$
is below
$
g
(
a
)
$
in the ordering for
$
A
_
o
$
.
\item
Given a preomain
$
A
$
, we can form the predomain
$
\later
A
$
whose underlying
type is
$
\later
\ty
{
A
}$
. We define
$
\tilde
{
x
}
\le
_{
\later
A
}
\tilde
{
y
}$
to be
$
\later
_
t
(
\tilde
{
x
}_
t
\le
_
A
\tilde
{
y
}_
t
)
$
.
\end{itemize}
...
...
@@ -148,14 +157,15 @@ Formally, we define this ordering as follows:
We also define a heterogeneous version of this ordering between the lifts of two
different predomains
$
A
$
and
$
B
$
, parameterized by a relation
$
R
$
between
$
A
$
and
$
B
$
.
\subsection
{
Step-Insensitive Relation
}
\subsection
{
Step-Insensitive
Bisimilarity
Relation
}
We define another ordering on
$
\li
A
$
, called
the
``step-insensitive
ordering'' or
``weak bisimilarity
'',
written
$
l
\bisim
l'
$
.
We define another ordering on
$
\li
A
$
, called ``step-insensitive
bisimilarity"
or
``weak bisimilarity
"
written
$
l
\bisim
l'
$
.
Intuitively, we say
$
l
\bisim
l'
$
if they are equivalent ``up to delays''.
We introduce the notation
$
x
\sim
_
A y
$
to mean
$
x
\le
_
A y
$
and
$
y
\le
_
A x
$
.
The weak bisimilarity relation is defined by guarded fixpoint as follows:
% TODO if A is a poset, then we can just say that x = y
%
The step-insensitive bisimilarity relation is defined by guarded fixpoint as follows:
\begin{align*}
&
\mho
\bisim
\mho
\\
...
...
@@ -181,13 +191,37 @@ The weak bisimilarity relation is defined by guarded fixpoint as follows:
\text
{
for some
$
n
$
and
$
y :
\ty
{
A
}$
such that
$
x
\sim
_
A y
$
}
\end{align*}
When both sides are
$
\eta
$
, then we ensure that the underlying values are related.
When one side is a
$
\theta
$
and the other is
$
\eta
x
$
(i.e., one side steps),
we stipulate that the
$
\theta
$
-term runs to
$
\eta
y
$
where
$
x
$
is related to
$
y
$
.
Similarly when one side is
$
\theta
$
and the other
$
\mho
$
.
If both sides step, then we allow one time step to pass and compare the resulting terms.
In this way, the definition captures the intuition of terms being equivalent up to
delays.
It can be shown (by
\lob
-induction) that the step-sensitive relation is symmetric.
However, it can also be shown that this relation is
\emph
{
not
}
transitive:
One can prove within Clocked Cubical Type Theory
that if this relation were transitive, then in fact it would be trivial in that
$
l
\bisim
l'
$
for all
$
l, l'
$
.
This issue will be resolved when we consider the relation's
\emph
{
globalization
}
.
\subsection
{
Error Domains
}
While value types will be interpreted as predomains, we also need a semantics
for computation types. This will be in the form of
\emph
{
error domains
}
, of which the
Lift monad is a prototypical example. For a fixed clock
$
k
$
, an error domain
$
A
$
consists of a predomain (which we also denote by
$
A
$
when there is no risk of confusion),
along with a bottom element
$
\mho
_
A
$
and a
$
\later
$
-algebra
$
\theta
_
A
\colon
\later
^
k A
\monto
A
$
.
% TODO function space as error domain?
\subsection
{
Globalization
}
\subsection
{
Globalization
}
\label
{
sec:globalization
}
Recall that in the above definitions, any occurrences of
$
\later
$
were with
re
p
sect to a fixed clock
$
k
$
. Intuitively, this corresponds to a step-indexed set.
res
p
ect to a fixed clock
$
k
$
. Intuitively, this corresponds to a step-indexed set.
It will be necessary to consider the ``globalization'' of these definitions,
i.e., the ``global'' behavior of the type over all potential time steps.
This is accomplished in the type theory by
\emph
{
clock quantification
}
\cite
{
atkey-mcbride2013
}
,
...
...
@@ -198,10 +232,124 @@ the usual semantics in the category of sets.
\section
{
Semantics
}
\label
{
sec:semantics
}
\subsection
{
Step-indexed Semantics
}
We give a semantics to the step-sensitive lambda calculus
$
\intlc
$
we defined
in Section
\ref
{
sec:step-sensitive-lc
}
.
%
Much of the semantics is similar to a normal call-by-value denotational semantics;
we highlight the differences.
Recall that we will interpret value types as predomains, and computation types
as error domains. Value type contexts
$
\Gamma
=
x
_
1
\colon
A
_
1
,
\dots
, x
_
n
\colon
A
_
n
$
will be interpreted as the product
$
\sem
{
A
_
1
}
\times
\cdots
\times
\sem
{
A
_
n
}$
, and
computation type contexts
$
\Delta
=
\Delta
_
\Sigma
,
\Delta
|
_
V
$
will be interpreted as a pair
$
(
\delta
_
\Sigma
,
\delta
_
V
)
$
where
$
\delta
_
\Sigma
$
is either empty or
$
\sem
{
B
}$
.
The semantics of the dynamic type
$
\dyn
$
is the predomain
$
\Dyn
$
introduced in Section
\ref
{
sec:predomains
}
.
%
The interpretation of a value
$
\hasty
{
\Gamma
}
V A
$
will be a monotone function from
$
\sem
{
\Gamma
}$
to
$
\sem
{
A
}$
. Likewise, a term
$
\hasty
{
\Delta
}
M
{
\Ret
{
A
}}$
will be interpreted
as a monotone function from
$
\sem
{
\Delta
}$
to
$
\sem
{
\Ret
{
A
}}
=
\li
\sem
{
A
}$
.
Recall that
$
\Dyn
$
is isomorphic to
$
\Nat\,
+
\later
(
\Dyn
\monto
\li
\Dyn
)
$
.
Thus, the semantics of
$
\injnat
{
\cdot
}$
and
$
\injarr
{
\cdot
}$
are simply the
injections
$
\inl
$
and
$
\inr
$
.
The interpretation of
$
\lda
{
x
}{
M
}$
works as follows. Recall by the typing rule for
lambda that
$
\hasty
{
\cdot
,
\Gamma
, x : A
_
i
}
M
{
\Ret
{
A
_
o
}}$
, so the interpretation of
$
M
$
has type
$
\{
*
\}
\times
(
\sem
{
\Gamma
}
\times
\sem
{
A
_
i
}
)
$
to
$
\sem
{
A
_
o
}$
.
The interpretation of lambda is thus a function (in the ambient type theory) that takes
a value
$
a
$
representing the argument and applies it (along with
$
\gamma
$
) as argument to
the interpretation of
$
M
$
.
%
The interpretation of bind and of application both make use the monadic extend function on
$
\li
A
$
.
%
The interpretation of case-nat and case-arrow is simply a case inspection on the
interpretation of the scrutinee, which has type
$
\Dyn
$
.
\vspace
{
2ex
}
\noindent
Types:
\begin{align*}
\sem
{
\nat
}
&
=
\Nat
\\
\sem
{
\dyn
}
&
=
\Dyn
\\
\sem
{
A
\ra
A'
}
&
=
\sem
{
A
}
\To
\sem
{
A'
}
\\
\sem
{
\later
A
}
&
=
\,
\later
\sem
{
A
}
\\
\sem
{
\Ret
A
}
&
=
\li
\sem
{
A
}
\end{align*}
% Contexts:
% TODO check these, especially the semantics of bind, case-nat, and case-arr
% with respect to their context argument
\noindent
Values and terms:
\begin{align*}
\sem
{
\zro
}
&
=
\lambda
\gamma
. 0
\\
\sem
{
\suc\,
V
}
&
=
\lambda
\gamma
. (
\sem
{
V
}
\,
\gamma
) + 1
\\
\sem
{
x
\in
\Gamma
}
&
=
\lambda
\gamma
.
\gamma
(x)
\\
\sem
{
\lda
{
x
}{
M
}}
&
=
\lambda
\gamma
.
\lambda
a .
\sem
{
M
}
\,
(*,
\,
(
\gamma
, a))
\\
\sem
{
\injnat
{
V
_
n
}}
&
=
\lambda
\gamma
.
\inl\,
(
\sem
{
V
_
n
}
\,
\gamma
)
\\
\sem
{
\injarr
{
V
_
f
}}
&
=
\lambda
\gamma
.
\inr\,
(
\sem
{
V
_
f
}
\,
\gamma
)
\\
[2ex]
\sem
{
\nxt\,
V
}
&
=
\lambda
\gamma
.
\nxt
(
\sem
{
V
}
\,
\gamma
)
\\
\sem
{
\theta
}
&
=
\lambda
\gamma
.
\theta
\\
%
\sem
{
\err
_
B
}
&
=
\lambda
\delta
.
\mho
\\
\sem
{
\ret\,
V
}
&
=
\lambda
\gamma
.
\eta\,
\sem
{
V
}
\\
\sem
{
\bind
{
x
}{
M
}{
N
}}
&
=
\lambda
\delta
.
\ext
{
(
\lambda
x .
\sem
{
N
}
\,
(
\delta
, x))
}
{
\sem
{
M
}
\,
\delta
}
\\
\sem
{
V
_
f
\,
V
_
x
}
&
=
\lambda
\gamma
.
\ext
{
(
\lambda
f . (
\ext
{
f
}
{
\sem
{
V
_
x
}
\,
\gamma
}
))
}
{
(
\sem
{
V
_
f
}
\,
\gamma
)
}
\\
\sem
{
\casenat
{
V
}{
M
_{
no
}}{
n
}{
M
_{
yes
}}}
&
=
\lambda
\delta
.
\text
{
case
$
(
\sem
{
V
}
\,
\delta
)
$
of
}
\\
&
\quad\quad\quad\quad
\alt
\inl
(n)
\to
\sem
{
M
_{
yes
}}
(n)
\\
&
\quad\quad\quad\quad
\alt
\inr
(
\tilde
{
f
}
)
\to
\sem
{
M
_{
no
}}
\\
\sem
{
\casearr
{
V
}{
M
_{
no
}}{
\tilde
{
f
}}{
M
_{
yes
}}}
&
=
\lambda
\delta
.
\text
{
case
$
(
\sem
{
V
}
\,
\delta
)
$
of
}
\\
&
\quad\quad\quad\quad
\alt
\inl
(n)
\to
\sem
{
M
_{
no
}}
\\
&
\quad\quad\quad\quad
\alt
\inr
(
\tilde
{
f
}
)
\to
\sem
{
M
_{
yes
}}
(
\tilde
{
f
}
)
\end{align*}
% TODO
% \noindent Relations:
% \begin{align*}
% %
% \end{align*}
\begin{comment}
\subsection
{
Global Semantics
}
Having defined the above step-indexed semantics, we now pass to a ``global''
semantics that does not involve any step-indexing. The resulting semantics is still
intensional in that terms that produce the same value in a different number of steps
will be distinct.
We define
\[
\semgl
{
\cdot
}
=
\forall
(
\kpa
\colon
\Clock
)
.
\,
\sem
{
\cdot
}
[
\kpa
]
.
\]
Note that for a term
$
M
$
of type
$
\Ret
{
A
}$
, the semantics has type
$
\sem
{
M
}
\colon
\sem
{
\Delta
}
\monto
\sem
{
\Ret
{
A
}}
=
\sem
{
\Delta
}
\monto
\li
\sem
{
A
}$
.
In the case where
$
\Delta
$
is the empty context, i.e., when
$
M
$
is a closed term,
then this is equivalent to
$
\li
\sem
{
A
}$
.
Then the global semantics in this case is
$
\forall
\kappa
.
\liclk
{
\kappa
}
\sem
{
A
}$
.
We can show in Clocked Cubical Type Theory this type satisfies a coinductive unfolding property
\[
\forall
\kappa
.
\li
\sem
{
A
}
\cong
\sem
{
A
}
+
1
\,
+
(
\forall
\kappa
.
\li
\sem
{
A
}
)
.
\]
\end{comment}
% Machines
% We then define a relation $\Dwn^n$ between terms of type $T$ and $\Machine {\sem{T}}$ by
% \subsection{Extensional Collapse}
\subsection
{
Relational Semantics
}
%
\subsection{Relational Semantics}
\subsubsection
{
Term Precision via the Step-Sensitive Error Ordering
}
%
\subsubsection{Term Precision via the Step-Sensitive Error Ordering}
% Homogeneous vs heterogeneous term precision
% \subsection{Logical Relations Semantics}
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