module Expressions: sig .. end
This module defines the syntax of expressions, as manipulated by the
type-checker. This module also defines various expression-specific
manipulation functions, esp. w.r.t. binders.
The definition of expressions
type tag_update_info = SurfaceSyntax.tag_update_info
type field = SurfaceSyntax.field
type pattern =
The type of patterns. We don't have type annotations anymore, they have been
transformed into type annotations onto the corresponding expression, i.e.
EConstraint nodes.
type rec_flag = SurfaceSyntax.rec_flag =
| |
Nonrecursive |
| |
Recursive |
type expression =
This is not very different from SurfaceSyntax.expression. Some nodes such
as ESequence have been removed.
type tapp =
type patexpr = pattern * expression
type declaration =
type declaration_group = declaration list
type sig_item = Variable.name * TypeCore.typ
type toplevel_item =
type implementation = toplevel_item list
type interface = toplevel_item list
Substitution functions
Of course, we have many more substitution functions, since now all the
substitution functions for types have to be extended to expressions and
patterns. The naming convention is as follows:
tsubst_X substitutes a type for an index in an X
esubst_X substitutes an expression for an index in an X
tpsubst_X substitutes a var for a type in an X
epsubst_X substitutes a var for an expression an X
Because most of the things are done through the "substitution kit" (see
below), most of the variants for substitution functions are *not* exposed to
the client code.
Convenience helpers
val e_unit : expression
The () (unit) expression.
val p_unit : pattern
The () (unit) pattern.
val eunloc : expression -> expression
Remove any ELocated node in front of an expression.
Substitution functions for types.
val tsubst_toplevel_items : TypeCore.typ ->
TypeCore.db_index ->
toplevel_item list -> toplevel_item list
val tpsubst_expr : TypeCore.env ->
TypeCore.typ ->
TypeCore.var -> expression -> expression
Substitution functions for expressions.
val esubst_toplevel_items : expression ->
TypeCore.db_index ->
toplevel_item list -> toplevel_item list
val epsubst : TypeCore.env ->
expression ->
TypeCore.var -> expression -> expression
Binding functions
type substitution_kit = {
}
To tame the combinatorial explosion, the binding functions in this module
return a substitution kit. That is to say, once you've bound type vars or
term vars, you're given a set of functions that you can apply on whatever you
need to open the binders. You are also given the list of (open) variables.
val bind_evars : TypeCore.env ->
TypeCore.type_binding list -> TypeCore.env * substitution_kit
Bind a set of term variables (let-bindings).
val bind_vars : TypeCore.env ->
SurfaceSyntax.type_binding list ->
TypeCore.env * substitution_kit
Bind a set of type variables (Λ-bindings).
val bind_patexprs : TypeCore.env ->
rec_flag ->
(pattern * expression) list ->
TypeCore.env * (pattern * expression) list *
substitution_kit
Bind a set of multiple bindings (
and keyword). The bindings may be
mutually recursive. There is also a set of expressions on the right-hand-side
of each
= sign. The variables will also be opened there, and this function
takes care of doing it properly depending on whether these are recursive
bindings or not.
It is then up to the client code to open these variables in the body of the
multiple bindings. Consider for instance "let rec x = e1 and y = e2 in e"; this
function will correctly open "x" and "y" in "e1" and "e2" but you must use the
substitution kit to open "x" and "y" in "e".
module ExprPrinter: sig .. end
Our not-so-pretty printer for expressions.