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
e6082718
Commit
e6082718
authored
6 years ago
by
Max New
Browse files
Options
Downloads
Patches
Plain Diff
judgmental structure and casts for gradual call by push value
parent
3fa7a71f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gcbpv.tex
+310
-0
310 additions, 0 deletions
gcbpv.tex
with
310 additions
and
0 deletions
gcbpv.tex
0 → 100644
+
310
−
0
View file @
e6082718
\documentclass
{
article
}
\usepackage
{
amsmath,amssymb
}
\usepackage
{
tikz-cd
}
\usepackage
{
mathpartir
}
\newtheorem
{
theorem
}{
Theorem
}
\newtheorem
{
definition
}{
Definition
}
\newcommand
{
\vtype
}{
\,\,\text
{
val type
}}
\newcommand
{
\ctype
}{
\,\,\text
{
comp type
}}
\newcommand
{
\ctx
}{
\,\,\text
{
ctx
}}
\newcommand
{
\pipe
}{
\,\,
|
\,\,
}
\newcommand
{
\hole
}{
\bullet
}
\renewcommand
{
\u
}{
\underline
}
\newcommand
{
\ltdyn
}{
\sqsubseteq
}
\newcommand
{
\ltdynv
}{
\mathrel
{
\sqsubseteq
_
V
}}
\newcommand
{
\ltdynt
}{
\mathrel
{
\sqsubseteq
_
T
}}
\newcommand
{
\dyn
}{{
?
}}
\newcommand
{
\upcast
}
[2]
{
\langle
{
#2
}
\leftarrowtail
{
#1
}
\rangle
}
\newcommand
{
\dncast
}
[2]
{
\langle
{
#1
}
\twoheadleftarrow
{
#2
}
\rangle
}
\newcommand
{
\Set
}{
\text
{
Set
}}
\newcommand
{
\relto
}{
\to
}
\newcommand
{
\M
}{
\mathcal
{
M
}}
\newcommand
{
\sq
}{
\square
}
\newcommand
{
\lett
}{
\text
{
let
}
\,\,
}
\begin{document}
\title
{
Gradual Call-By-Push-Value
}
\author
{
Max S. New, Daniel R. Licata and Amal Ahmed
}
\maketitle
There are 5 basic judgments of call-by-push-value: value types,
computation types, values (many value types as input, value type as
output), terms (many value types as input, computation type as output)
and stacks (many value types and one computation type as input,
computation type as output) (also equality?).
%
Gradual Call-by-push-value adds an ordering form for each of these
judgments: value type dynamism, computation type dynamism, value
dynamism, term dynamism and stack dynamism.
\begin{figure}
\begin{mathpar}
A
\vtype
\and
\inferrule
{}
{
A
_
1
\ltdyn
A
_
2
}
\\
\underline
{
B
}
\ctype\and
\inferrule
{}
{
\underline
{
B
}_
1
\ltdyn
\underline
{
B
}_
2
}
\\
\Gamma
\ctx
\Phi
:
\Gamma
_
1
\ltdyn
\Gamma
_
2
\\
\inferrule
{
\Gamma
\ctx
\and
A
\vtype
}
{
\Gamma
\vdash
v : A
}
\inferrule
{
\Phi
:
\Gamma
_
1
\ltdyn
\Gamma
_
2
\and
A
_
1
\ltdyn
A
_
2
}
{
\Phi
\vdash
v
_
1
\ltdyn
v
_
2 : A
_
1
\ltdyn
A
_
2
}
\\
\inferrule
{
\Gamma
\ctx
\and
B
\ctype
}
{
\Gamma
\vdash
M :
\underline
B
}
\inferrule
{
\Phi
\vdash
\Gamma
_
1
\ltdyn
\Gamma
_
2
\ctx
\and
\Gamma
_
1
\vdash
M
_
1 :
\u
B
_
1
\and
\Gamma
_
2
\vdash
M
_
2 :
\u
B
_
2
\and
\u
B
_
1
\ltdyn
\u
B
_
2
}
{
\Phi
\vdash
M
_
1
\ltdyn
M
_
2 :
\u
B
_
1
\ltdyn
\u
B
_
2
}
\\
\inferrule
{
\Gamma\ctx
\and
\u
B
\ctype
\and
\u
C
\ctype
}
{
\Gamma\pipe
\hole
:
\u
B
\vdash
S :
\u
C
}
\inferrule
{
\Phi
:
\Gamma
_
1
\ltdyn
\Gamma
_
2
\and
\u
B
_
1
\ltdyn
\u
B
_
2
\and
{
\Gamma
_
1
\pipe
\hole
:
\u
B
_
1
\vdash
S
_
1 :
\u
C
_
1
}
\and
{
\Gamma
_
2
\pipe
\hole
:
\u
B
_
2
\vdash
S
_
2 :
\u
C
_
2
}
\and
\u
C
_
1
\ltdyn
\u
C
_
2
}
{
\Phi\pipe
\hole
\ltdyn
\hole
:
\u
B
_
1
\ltdyn
\u
B
_
2
\vdash
S
_
1
\ltdyn
S
_
2 :
\u
C
_
1
\ltdyn
\u
C
_
2
}
\end{mathpar}
\caption
{
GCBPV Judgment Presuppositions
}
\end{figure}
Call-by-push-value includes 5 kinds of substitution: we can substitute
values for variables in values, terms and stacks and we can plug
terms and stacks into the hole
$
\hole
$
of a stack.
%
Furthermore, there are the 2 forms of identity: value variable usage
in a value and hole usage in a stack.
%
The orderings of GCBPV are all congruences with respect to these
notions of composition and their corresponding identities.
%
Additionally, there are rules making each of the orderings into
\emph
{
preorders
}
: i.e., there are reflexivity and transitivity rules
for each.
\begin{figure}
\begin{mathpar}
\inferrule
{}
{
\Gamma
,x:A,
\Gamma
'
\vdash
x : A
}
\inferrule
{}
{
\Phi
,x
_
1
\ltdyn
x
_
2 : A
_
1
\ltdyn
A
_
2,
\Phi
'
\vdash
x
_
1
\ltdyn
x
_
2 : A
_
1
\ltdyn
A
_
2
}
\\
\inferrule
{
\gamma
:
\prod
_{
x' : A'
\in
\Gamma
'
}
\Gamma
\vdash
\cdot
: A'
\and
\Gamma
\vdash
v : A
}
{
\Gamma
\vdash
v[
\gamma
] : A
}
\inferrule
{
\Phi
'
\vdash
v
_
1
\ltdyn
v
_
2 : A
_
1
\ltdyn
A
_
2
\and
\forall
(x
_
1'
\ltdyn
x
_
2' : A
_
1'
\ltdyn
A
_
2'
\in
\Phi
').
\Phi
\vdash
\gamma
_
1(x
_
1')
\ltdyn
\gamma
_
2(x
_
2') : A
_
1'
\ltdyn
A
_
2'
}
{
\Phi
\vdash
v
_
1[
\gamma
_
1]
\ltdyn
v
_
2[
\gamma
_
2] : A
_
1
\ltdyn
A
_
2
}
\inferrule
{
\gamma
:
\prod
_{
x' : A'
\in
\Gamma
'
}
\Gamma
\vdash
\cdot
: A'
\and
\Gamma
\vdash
M :
\u
B
}
{
\Gamma
\vdash
M[
\gamma
] :
\u
B
}
\inferrule
{
\Phi
'
\vdash
M
_
1
\ltdyn
M
_
2 :
\u
B
_
1
\ltdyn
\u
B
_
2
\and
\forall
(x
_
1'
\ltdyn
x
_
2' : A
_
1'
\ltdyn
A
_
2'
\in
\Phi
').
\Phi
\vdash
\gamma
_
1(x
_
1')
\ltdyn
\gamma
_
2(x
_
2') : A
_
1'
\ltdyn
A
_
2'
}
{
\Phi
\vdash
M
_
1[
\gamma
_
1]
\ltdyn
M
_
2[
\gamma
_
2] :
\u
B
_
1
\ltdyn
\u
B
_
2
}
\inferrule
{
\gamma
:
\prod
_{
x' : A'
\in
\Gamma
'
}
\Gamma
\vdash
\cdot
: A'
\and
\Gamma\pipe
\u
B
\vdash
S :
\u
C
}
{
\Gamma\pipe
\u
B
\vdash
S[
\gamma
] :
\u
C
}
\inferrule
{
\Phi
'
\pipe
\hole\ltdyn
\hole
:
\u
B
_
1
\ltdyn
\u
B
_
2
\vdash
S
_
1
\ltdyn
S
_
2 :
\u
C
_
1
\ltdyn
\u
C
_
2
\and
\forall
(x
_
1'
\ltdyn
x
_
2' : A
_
1'
\ltdyn
A
_
2'
\in
\Phi
').
\Phi
\vdash
\gamma
_
1(x
_
1')
\ltdyn
\gamma
_
2(x
_
2') : A
_
1'
\ltdyn
A
_
2'
}
{
\Phi
\pipe
\hole\ltdyn
\hole
:
\u
B
_
1
\ltdyn
\u
B
_
2
\vdash
S
_
1[
\gamma
_
1]
\ltdyn
S
_
2[
\gamma
_
2] :
\u
C
_
1
\ltdyn
\u
C
_
2
}
\inferrule
{}{
\Gamma\pipe
\hole
:
\u
B
\vdash
\hole
:
\u
B
}
\inferrule
{}{
\Phi\pipe
\hole
\ltdyn
\hole
:
\u
B
_
1
\ltdyn
\u
B
_
2
\vdash
\ltdyn
\hole
:
\u
B
_
1
\ltdyn
\u
B
_
2
}
\inferrule
{
\Gamma
\vdash
M :
\u
B
\and
\Gamma
\pipe
\hole
:
\u
B
\vdash
S :
\u
C
}
{
\Gamma\pipe
\hole
:
\u
B
\vdash
S[M/
\hole
] :
\u
C
}
\inferrule
{
\Gamma
\pipe
\u
B
\vdash
S :
\u
B'
\and
\Gamma
\pipe
\hole
:
\u
B'
\vdash
S' :
\u
B''
}
{
\Gamma\pipe
\hole
:
\u
B
\vdash
S'[S/
\hole
] :
\u
B''
}
\end{mathpar}
\caption
{
GCBPV Basic Judgmental Rules 1 (Identities, Substitutions)
}
\end{figure}
\begin{figure}
\begin{mathpar}
\inferrule
{}
{
A
\ltdyn
A
}
\inferrule
{
A
_
1
\ltdyn
A
_
2
\and
A
_
2
\ltdyn
A
_
3
}
{
A
_
1
\ltdyn
A
_
3
}
\\
\inferrule
{}
{
\u
B
\ltdyn
\u
B
}
\inferrule
{
\u
B
_
1
\ltdyn
\u
B
_
2
\and
\u
B
_
2
\ltdyn
\u
B
_
3
}
{
\u
B
_
1
\ltdyn
\u
B
_
3
}
\\
\inferrule
{}
{
\Phi
_{
\Gamma
}
:
\Gamma
\ltdyn
\Gamma
}
\inferrule
{
\Phi
:
\Gamma
_
1
\ltdyn
\Gamma
_
2
\and
\Phi
' :
\Gamma
_
2
\ltdyn
\Gamma
_
3
}
{
\Phi
'' :
\Gamma
_
1
\ltdyn
\Gamma
_
3
}
\\
\inferrule
{
\Gamma
\vdash
v : A
}
{
\Gamma
\ltdyn
\Gamma
\vdash
v
\ltdyn
v : A
\ltdyn
A
}
\inferrule
{
\Phi
\vdash
v
_
1
\ltdyn
v
_
2 : A
_
1
\ltdyn
A
_
2
\and
\Phi
'
\vdash
v
_
2
\ltdyn
v
_
3 : A
_
2
\ltdyn
A
_
3
\and
}
{
\Phi
''
\vdash
v
_
1
\ltdyn
v
_
3 : A
_
1
\ltdyn
A
_
3
}
\\
\inferrule
{
\Gamma
\vdash
M :
\u
B
}
{
\Gamma
\vdash
M
\ltdyn
M :
\u
B
\ltdyn
\u
B
}
\inferrule
{
\Phi
\vdash
M
_
1
\ltdyn
M
_
2 :
\u
B
_
1
\ltdyn
\u
B
_
2
\and
\Phi
'
\vdash
M
_
2
\ltdyn
M
_
3 :
\u
B
_
2
\ltdyn
\u
B
_
3
\and
}
{
\Phi
''
\vdash
M
_
1
\ltdyn
M
_
3 :
\u
B
_
1
\ltdyn
\u
B
_
3
}
\\
\inferrule
{
\Gamma\pipe
\hole
:
\u
B
\vdash
M :
\u
C
}
{
\Gamma\pipe
\hole
:
\u
B
\vdash
M
\ltdyn
M :
\u
C
\ltdyn
\u
C
}
\inferrule
{
\Phi
\pipe
\hole
:
\u
B
_
1
\ltdyn
\u
B
_
2
\vdash
S
_
1
\ltdyn
S
_
2 :
\u
C
_
1
\ltdyn
\u
C
_
2
\and
\Phi
'
\pipe
\hole
:
\u
B
_
2
\ltdyn
\u
B
_
3
\vdash
S
_
2
\ltdyn
S
_
3 :
\u
C
_
2
\ltdyn
\u
C
_
3
\and
}
{
\Phi
''
\pipe
\hole
:
\u
B
_
1
\ltdyn
\u
B
_
3
\vdash
S
_
1
\ltdyn
S
_
3 :
\u
C
_
1
\ltdyn
\u
C
_
3
}
\end{mathpar}
\caption
{
GCBPV Basic Judgmental Rules 2 (Reflexivities, Transitivities)
}
\end{figure}
Errors are least terms at every computation type (not stacks).
%
The dynamic type is probably a greatest
\emph
{
value type
}
.
%
Casts are, naturally, the most interesting case.
%
A na
\"
ive attempt to add casts in the style of cbn gradual type theory
(TODO: cite) would be to add an upcast and downcast
\emph
{
values
}
for
every value type dynamism judgment and upcast and downcast
\emph
{
stacks
}
for every computation type dynamism judgment.
%
However, this does not match pre-existing work on gradual typing: if a
downcast is a value, then that means a type error is a value?
%
Dually, if a function upcast were a stack, that would mean it
\emph
{
has
}
to call the function it is casting, but if the downcast on
the input fails, the function will never be invoked.
%
We have forgotten the translation of call-by-name into
call-by-push-value: the call-by-name casts would not be stacks
$
\u
B
\multimap
\u
C
$
but
\emph
{
co-Kleisli
}
arrows
$
U
(
\u
B
)
\to
\u
C
$
.
%
While this gives us a correct translation of cbn GTT, it violates the
judgmental approach since now casts need the presence of the
$
U
$
type
in order to be defined.
%
Furthermore, our original na
\"
ive attempt had something going for it:
upcasts in call-by-value
\emph
{
are
}
pure functions and downcasts in
call-by-name
\emph
{
are
}
linear, but there is no way to prove this if
we assume casts are given by Kleisli and co-Kleisli morphisms.
Fortunately, there is a simple resolution to all of these problems
that is actually
\emph
{
simpler
}
than our na
\"
ive approach: value type
dynamism induces a pure value upcast and computation type dynamism
induces a linear stack downcast, and
\emph
{
no other casts are
primitive
}
.
%
The downcast on value types and upcast on computation types will then
be
\emph
{
derived
}
using the
$
F,U
$
adjoint type constructors, which
will both be defined to be
\emph
{
monotone
}
with respect to type
dynamism.
\begin{figure}
\begin{mathpar}
\inferrule
{
\Gamma
\vdash
v : A
_
1
\and
A
_
1
\ltdyn
A
_
2
}
{
\Gamma
\vdash
\upcast
{
A
_
1
}{
A
_
2
}
v : A
_
2
}
\inferrule
{
A
_
1
\ltdyn
A
_
2
}
{
x
_
1 : A
_
1
\vdash
x
_
1
\ltdyn
\upcast
{
A
_
1
}{
A
_
2
}
x
_
1 : A
_
1
\ltdyn
A
_
2
}
\inferrule
{
A
_
1
\ltdyn
A
_
2
}
{
x
_
1
\ltdyn
x
_
2 : A
_
1
\ltdyn
A
_
2
\vdash
\upcast
{
A
_
1
}{
A
_
2
}
x
_
1
\ltdyn
x
_
2 : A
_
2
}
\\
\inferrule
{
\Gamma\pipe
\hole
:
\u
C
\vdash
S :
\u
B
_
2
\and
\u
B
_
1
\ltdyn
\u
B
_
2
}
{
\Gamma
\pipe
\hole
:
\u
C
\vdash
\dncast
{
\u
B
_
1
}{
\u
B
_
2
}
S :
\u
B
_
1
}
\inferrule
{
\Gamma
\vdash
M :
\u
B
_
2
\and
\u
B
_
1
\ltdyn
\u
B
_
2
}
{
\Gamma
\vdash
\dncast
{
\u
B
_
1
}{
\u
B
_
2
}
M :
\u
B
_
1
}
\inferrule
{
\u
B
_
1
\ltdyn
\u
B
_
2
}
{
\cdot\pipe
\hole
:
\u
B
_
2
\vdash
\dncast
{
\u
B
_
1
}{
\u
B
_
2
}{
\hole
}
\ltdyn
\hole
:
\u
B
_
1
\ltdyn
\u
B
_
2
}
\inferrule
{
\u
B
_
1
\ltdyn
\u
B
_
2
}
{
\cdot\pipe
\hole
\ltdyn
\hole
:
\u
B
_
1
\ltdyn
\u
B
_
2
\vdash
{
\hole
}
\ltdyn
\dncast
{
\u
B
_
1
}{
\u
B
_
2
}
\hole
:
\u
B
_
1
}
\end{mathpar}
\caption
{
Upcasts and Downcasts (Would be simpler with a Stoup)
}
\end{figure}
\end{document}
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