Parameter MakeTrans.F

Define the semantics of our abstract language.

Statements and expressions.

type 'a stm = 'a T.from_stm

A statement, generally some side-effecting code.

type 'a obs

The final evaluation result.

val observe : 'a stm -> 'a obs

Observe the evaluation result after all transformations have applied.

type 'a exp = 'a T.from_exp

An expression.

val return : 'a exp -> 'a stm

Return value 'a from a function.

val stm : unit exp -> unit stm
type 'a ref

A mutable reference variable. This is not compatible with expressions.

val let| : unit stm -> (unit -> 'a stm) -> 'a stm

Evaluate a unit statement.

val let$ : (string * 'a exp) -> ('a exp -> 'b stm) -> 'b stm

Define a new immutable binding. The string is used for pretty-printing.

val let& : (string * 'a exp) -> ('a ref -> 'b stm) -> 'b stm

Define a new reference variable. The string is used for pretty-printing.

val (!) : 'a ref -> 'a exp
val (:=) : 'a ref -> 'a exp -> unit stm
val incr : int ref -> unit stm

Functions.

val lambda : ('a exp -> 'b stm) -> ('a -> 'b) exp
val (@@) : ('a -> 'b) exp -> 'a exp -> 'b exp

Control flow.

val if_else : bool exp -> then_:(unit -> 'a stm) -> else_:(unit -> 'a stm) -> 'a stm
val while_ : ('a exp -> bool exp) -> 'a ref -> (unit -> unit stm) -> unit stm

Standard values.

val unit : unit stm
val not : bool exp -> bool exp
val int : int -> int exp
val float : float -> float exp
val string : string -> string exp
val bool : bool -> bool exp
val (=) : 'a exp -> 'a exp -> bool exp
val pair : ('a exp * 'b exp) -> ('a * 'b) exp
val unpair : ('a * 'b) exp -> 'a exp * 'b exp
val string_of_int : int exp -> string exp
val string_of_float : float exp -> string exp
val string_of_bool : bool exp -> string exp

Sequences.

val uncons : 'a Stdlib.Seq.t exp -> nil:(unit -> 'b stm) -> cons:('a exp -> 'a Stdlib.Seq.t exp -> 'b stm) -> 'b stm
val generator : (('a exp -> unit stm) -> unit stm) -> 'a Stdlib.Seq.t exp
val iter : 'a Stdlib.Seq.t exp -> ('a exp -> unit stm) -> unit stm

Strings and characters.

val string_to_seq : string exp -> char Stdlib.Seq.t exp
val match_char : char exp -> (char -> 'a stm) -> 'a stm

The given function applies to the following characters and it ignores all others: '&' '"' '\'' '>' '<' '/' '`' '=' .

Arrays.

val array : 'a exp array -> 'a array exp
val array_make : int -> 'a exp -> 'a array exp
val (.%()) : 'a array exp -> int exp -> 'a exp
val (.%()<-) : 'a array exp -> int exp -> 'a exp -> unit stm

Hash tables.

type 'a hashtbl := 'a Stdlib.Hashtbl.MakeSeeded(Stdlib.String).t
val hashtbl : (string exp * 'a exp) Stdlib.Seq.t -> 'a hashtbl exp
val hashtbl_create : unit -> 'a hashtbl exp
val (.%{}) : 'a hashtbl exp -> string exp -> 'a exp
val (.%{}<-) : 'a hashtbl exp -> string exp -> 'a exp -> unit stm
val hashtbl_mem : 'a hashtbl exp -> string exp -> bool exp
val hashtbl_to_seq : 'a hashtbl exp -> (string * 'a) Stdlib.Seq.t exp

Mutable string buffers.

val buffer_create : unit -> Stdlib.Buffer.t exp
val buffer_add_string : Stdlib.Buffer.t exp -> string exp -> unit stm
val buffer_add_char : Stdlib.Buffer.t exp -> char exp -> unit stm
val buffer_contents : Stdlib.Buffer.t exp -> string exp
val buffer_length : Stdlib.Buffer.t exp -> int exp

Promises.

type 'a promise

An asynchronous monad.

val promise : 'a exp -> 'a promise exp
val await : 'a promise exp -> 'a exp
val error : string exp -> 'a promise exp
val async_lambda : ('a exp -> 'b promise stm) -> ('a -> 'b promise) exp

This is necessary for JavaScript async/await syntax compatibility.

Data

type untyped
module type UNTYPED = sig ... end
val untyped : string -> ((module UNTYPED with type t = 'a) -> 'b stm) -> 'b stm

Make a new untyped wrapper. The string is used for pretty-printing.

module External : sig ... end

Data from the outside world that we need to decode.

Importing and exporting.

type import

Information to import a function from external code.

val import : import -> ((External.t -> string promise) exp -> 'a stm) -> 'a stm
val export : 'a exp -> 'a stm