Module Sce_core.Ast

Source-core syntax, parameterized by the representation of term variables.

type typ =
  1. | TInt
  2. | TBool
  3. | TString
  4. | TTop
  5. | TArr of typ * typ
  6. | TAnd of typ * typ
  7. | TOr of typ * typ
  8. | TRcd of string * typ
  9. | TSig of typ
  10. | TMarr of typ * typ
  11. | TVar of int
  12. | TMu of typ

TVar 0 is bound by the nearest enclosing TMu. TSig classifies structures; TMarr classifies module functors.

val subst_typ : int -> typ -> typ -> typ

subst_typ d replacement t replaces index d, increasing the target index under each TMu. replacement must be closed: no shifting or renumbering of other free variables is performed.

type sandbox =
  1. | Sandboxed
    (*

    A functor captures the empty environment.

    *)
  2. | Open
    (*

    A functor captures the ambient environment.

    *)
type lit =
  1. | Int of int
  2. | Bool of bool
  3. | String of string
type binop =
  1. | Add
  2. | Sub
  3. | Mul
  4. | Div
  5. | Mod
  6. | Lt
  7. | Le
  8. | Gt
  9. | Ge
  10. | Eq
  11. | Ne
  12. | Cat

Arithmetic and ordering use integers; equality uses matching primitive types; Cat concatenates strings.

type binder = string
val anon : binder

The conventional anonymous binder, "_".

type void = |

An empty type rules out Var in resolved terms.

type 'v exp =
  1. | Var of 'v
  2. | Query
  3. | Proj of 'v exp * int
  4. | Lit of lit
  5. | Unit
  6. | Lam of binder * typ * 'v exp
  7. | Box of 'v exp * 'v exp
    (*

    The first expression's value replaces the ambient environment.

    *)
  8. | Clos of 'v exp * typ * 'v exp
    (*

    Captured value environment, argument type, body.

    *)
  9. | App of 'v exp * 'v exp
  10. | Mrg of binder * 'v exp * 'v exp
    (*

    Its right operand sees the left value as one new binding.

    *)
  11. | Lrec of string * 'v exp
  12. | Rproj of 'v exp * string
  13. | Binop of binop * 'v exp * 'v exp
  14. | If of 'v exp * 'v exp * 'v exp
  15. | Mstruct of 'v exp
  16. | Mfunctor of sandbox * binder * typ * 'v exp
  17. | Mclos of 'v exp * typ * 'v exp
    (*

    Module closure with a captured value environment.

    *)
  18. | Mapp of 'v exp * 'v exp
  19. | Nmrg of 'v exp * 'v exp
    (*

    Both operands run in the same ambient environment.

    *)
  20. | Letb of binder * 'v exp * 'v exp
  21. | Openm of binder * 'v exp * 'v exp
    (*

    Bind a single labelled record's payload in the body.

    *)
  22. | Mlinkn of 'v exp * 'v exp
    (*

    Link every labelled import of a functor from a provider.

    *)
  23. | Inl of typ * 'v exp
    (*

    The annotation is the other, right summand.

    *)
  24. | Inr of typ * 'v exp
    (*

    The annotation is the other, left summand.

    *)
  25. | Case of 'v exp * binder * 'v exp * binder * 'v exp
    (*

    Each branch binds its injection payload at index zero.

    *)
  26. | Flam of binder * binder * typ * typ * 'v exp
    (*

    Recursive name, argument name, argument type, result type, body. The body sees the argument at index zero and itself at index one.

    *)
  27. | Fclos of 'v exp * typ * typ * 'v exp
    (*

    Recursive closure with a captured value environment.

    *)
  28. | Fold of typ * 'v exp
    (*

    Fold (body, e) has type TMu body; the annotation is the mu body.

    *)
  29. | Unfold of 'v exp

Query denotes the complete environment. Index zero selects the right component of a merge; higher indices follow the left spine, excluding its terminal base. Runtime environments conventionally start at Unit. Binder names are retained after resolution but evaluation ignores them.

type named = string exp
type nameless = void exp
val is_value : 'v exp -> bool

The runtime value predicate, including recursively valued environments and payloads. It does not check types or closure bodies.