Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
POTTIER Francois
alphaLib
Commits
503fef7f
Commit
503fef7f
authored
Feb 20, 2017
by
POTTIER Francois
Browse files
Split off [BindingFormsAbs].
parent
9c3d8921
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/BindingForms.ml
View file @
503fef7f
type
void
(* -------------------------------------------------------------------------- *)
(* The main effect of a binding construct is to cause the environment to be
enriched when the abstraction is traversed. The following visitor methods
define where the environment is enriched. *)
(* These methods do not know the type of the environment, and do not know how
it is enriched or looked up; the latter task is delegated to the virtual
methods [extend] and [lookup]. The implementation of these methods is
provided by separate ``kits''. *)
(* This module merges the visitor classes defined in the following modules:
(* We need several varieties of visitors, which is a bit painful. As of now,
[iter], [map], [endo], [iter2] are required: see [ToolboxInput]. *)
- [BindingFormsAbs], which provides abstractions of one name in one term;
(* The visitor methods are polymorphic in the type of terms. This is
important, as it means that one can use several instances of a binding
construct in a single type definition and still be able to construct
well-typed visitors. *)
- [BindingFormsUnbound], which provides a much richer combinator language
for defining complex binding constructs.
(*
Th
e virtual methods [extend] and [lookup] are not polymorphic in the types
of bound names and environments. On the contrary, each kit comes with
certain specific types of bound names and environments
. *)
Th
is module also defines dummy [visit_'bn] methods, which are never called
but must exist (because we expect the user-defined type of terms to be
parameterized over ['bn] and ['fn])
. *)
(* -------------------------------------------------------------------------- *)
(* A universal, concrete type of single-name abstractions. *)
(* The empty type [void] is used in the definition of the dummy methods
[visit_'bn] below. This allows us to statically ensure that these
methods are never called. *)
(* We wish to represent all kinds of abstractions -- e.g. in nominal style,
in de Bruijn style, etc. -- so we parameterize the abstraction over the
type ['bn] of the bound name and over the type ['term] of the body. This
makes this type definition almost trivial -- it is just a pair -- but it
still serves as a syntactic marker of where abstractions are located. *)
type
(
'
bn
,
'
term
)
abs
=
'
bn
*
'
term
type
void
(* -------------------------------------------------------------------------- *)
(* [iter] *)
class
virtual
[
'
self
]
iter
=
object
(
self
:
'
self
)
class
virtual
[
'
self
]
iter
=
object
(
_
:
'
self
)
method
private
visit_'bn
:
void
->
void
->
void
=
fun
_
_
->
assert
false
method
private
virtual
extend
:
'
bn
->
'
env
->
'
env
method
private
visit_abs
:
'
term
.
_
->
(
'
env
->
'
term
->
unit
)
->
'
env
->
(
'
bn
,
'
term
)
abs
->
unit
=
fun
_
visit_term
env
(
x
,
t
)
->
let
env'
=
self
#
extend
x
env
in
visit_term
env'
t
inherit
[
_
]
BindingFormsAbs
.
iter
end
...
...
@@ -61,20 +34,12 @@ end
(* [iter2] *)
class
virtual
[
'
self
]
iter2
=
object
(
self
:
'
self
)
class
virtual
[
'
self
]
iter2
=
object
(
_
:
'
self
)
method
private
visit_'bn
:
void
->
void
->
void
->
void
=
fun
_
_
_
->
assert
false
method
private
virtual
extend
:
'
bn1
->
'
bn2
->
'
env
->
'
env
method
private
visit_abs
:
'
term1
'
term2
.
_
->
(
'
env
->
'
term1
->
'
term2
->
'
z
)
->
'
env
->
(
'
bn1
,
'
term1
)
abs
->
(
'
bn2
,
'
term2
)
abs
->
'
z
=
fun
_
visit_term
env
(
x1
,
t1
)
(
x2
,
t2
)
->
let
env'
=
self
#
extend
x1
x2
env
in
visit_term
env'
t1
t2
inherit
[
_
]
BindingFormsAbs
.
iter2
end
...
...
@@ -82,21 +47,12 @@ end
(* [map] *)
class
virtual
[
'
self
]
map
=
object
(
self
:
'
self
)
class
virtual
[
'
self
]
map
=
object
(
_
:
'
self
)
method
private
visit_'bn
:
void
->
void
->
void
=
fun
_
_
->
assert
false
method
private
virtual
extend
:
'
bn1
->
'
env
->
'
bn2
*
'
env
method
private
visit_abs
:
'
term1
'
term2
.
_
->
(
'
env
->
'
term1
->
'
term2
)
->
'
env
->
(
'
bn1
,
'
term1
)
abs
->
(
'
bn2
,
'
term2
)
abs
=
fun
_
visit_term
env
(
x1
,
t1
)
->
let
x2
,
env'
=
self
#
extend
x1
env
in
let
t2
=
visit_term
env'
t1
in
x2
,
t2
inherit
[
_
]
BindingFormsAbs
.
map
end
...
...
@@ -104,23 +60,11 @@ end
(* [endo] *)
class
virtual
[
'
self
]
endo
=
object
(
self
:
'
self
)
class
virtual
[
'
self
]
endo
=
object
(
_
:
'
self
)
method
private
visit_'bn
:
void
->
void
->
void
=
fun
_
_
->
assert
false
method
private
virtual
extend
:
'
bn
->
'
env
->
'
bn
*
'
env
method
private
visit_abs
:
'
term
.
_
->
(
'
env
->
'
term
->
'
term
)
->
'
env
->
(
'
bn
,
'
term
)
abs
->
(
'
bn
,
'
term
)
abs
=
fun
_
visit_term
env
((
x1
,
t1
)
as
this
)
->
let
x2
,
env'
=
self
#
extend
x1
env
in
let
t2
=
visit_term
env'
t1
in
if
x1
==
x2
&&
t1
==
t2
then
this
else
x2
,
t2
inherit
[
_
]
BindingFormsAbs
.
endo
end
src/BindingFormsAbs.ml
0 → 100644
View file @
503fef7f
(* -------------------------------------------------------------------------- *)
(* A universal, concrete type of single-name abstractions. *)
(* We wish to represent all kinds of abstractions -- e.g. in nominal style,
in de Bruijn style, etc. -- so we parameterize the abstraction over the
type ['bn] of the bound name and over the type ['term] of the body. This
makes this type definition almost trivial -- it is just a pair -- but it
still serves as a syntactic marker of where abstractions are located. *)
type
(
'
bn
,
'
term
)
abs
=
'
bn
*
'
term
(* -------------------------------------------------------------------------- *)
(* The main effect of a binding construct is to cause the environment to be
enriched when the abstraction is traversed. The following visitor methods
define where the environment is enriched. *)
(* These methods do not know the type of the environment, and do not know how
it is enriched or looked up; the latter task is delegated to the virtual
methods [extend] and [lookup]. The implementation of these methods is
provided by separate ``kits''. *)
(* We need several varieties of visitors, which is a bit painful. As of now,
[iter], [map], [endo], [iter2] are required: see [ToolboxInput]. *)
(* The visitor methods are polymorphic in the type of terms. This is
important, as it means that one can use several instances of a binding
construct in a single type definition and still be able to construct
well-typed visitors. *)
(* The virtual methods [extend] and [lookup] are not polymorphic in the types
of bound names and environments. On the contrary, each kit comes with
certain specific types of bound names and environments. *)
(* -------------------------------------------------------------------------- *)
(* [iter] *)
class
virtual
[
'
self
]
iter
=
object
(
self
:
'
self
)
method
private
virtual
extend
:
'
bn
->
'
env
->
'
env
method
private
visit_abs
:
'
term
.
_
->
(
'
env
->
'
term
->
unit
)
->
'
env
->
(
'
bn
,
'
term
)
abs
->
unit
=
fun
_
visit_term
env
(
x
,
t
)
->
let
env'
=
self
#
extend
x
env
in
visit_term
env'
t
end
(* -------------------------------------------------------------------------- *)
(* [iter2] *)
class
virtual
[
'
self
]
iter2
=
object
(
self
:
'
self
)
method
private
virtual
extend
:
'
bn1
->
'
bn2
->
'
env
->
'
env
method
private
visit_abs
:
'
term1
'
term2
.
_
->
(
'
env
->
'
term1
->
'
term2
->
'
z
)
->
'
env
->
(
'
bn1
,
'
term1
)
abs
->
(
'
bn2
,
'
term2
)
abs
->
'
z
=
fun
_
visit_term
env
(
x1
,
t1
)
(
x2
,
t2
)
->
let
env'
=
self
#
extend
x1
x2
env
in
visit_term
env'
t1
t2
end
(* -------------------------------------------------------------------------- *)
(* [map] *)
class
virtual
[
'
self
]
map
=
object
(
self
:
'
self
)
method
private
virtual
extend
:
'
bn1
->
'
env
->
'
bn2
*
'
env
method
private
visit_abs
:
'
term1
'
term2
.
_
->
(
'
env
->
'
term1
->
'
term2
)
->
'
env
->
(
'
bn1
,
'
term1
)
abs
->
(
'
bn2
,
'
term2
)
abs
=
fun
_
visit_term
env
(
x1
,
t1
)
->
let
x2
,
env'
=
self
#
extend
x1
env
in
let
t2
=
visit_term
env'
t1
in
x2
,
t2
end
(* -------------------------------------------------------------------------- *)
(* [endo] *)
class
virtual
[
'
self
]
endo
=
object
(
self
:
'
self
)
method
private
virtual
extend
:
'
bn1
->
'
env
->
'
bn2
*
'
env
method
private
visit_abs
:
'
term
.
_
->
(
'
env
->
'
term
->
'
term
)
->
'
env
->
(
'
bn
,
'
term
)
abs
->
(
'
bn
,
'
term
)
abs
=
fun
_
visit_term
env
((
x1
,
t1
)
as
this
)
->
let
x2
,
env'
=
self
#
extend
x1
env
in
let
t2
=
visit_term
env'
t1
in
if
x1
==
x2
&&
t1
==
t2
then
this
else
x2
,
t2
end
src/alphaLib.mlpack
View file @
503fef7f
Atom
BindingForms
BindingFormsAbs
KitAvoid
KitAvoids
KitBa
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment