2022-01-30 00:55:42 +00:00
|
|
|
(** Purely functional queue, implemented as a pair of lists. *)
|
|
|
|
type 'a queue = { front : 'a list; back : 'a list }
|
|
|
|
|
2022-02-04 03:06:51 +00:00
|
|
|
(** Result type for error handling. *)
|
2022-01-30 00:55:42 +00:00
|
|
|
type 'a result =
|
|
|
|
| Error of string
|
|
|
|
| Success of 'a
|
|
|
|
|
|
|
|
(** Purely functional stack. *)
|
|
|
|
type 'a stack =
|
|
|
|
| Empty
|
|
|
|
| Stacked of 'a * 'a stack
|
|
|
|
|
2022-02-04 03:06:51 +00:00
|
|
|
(**A purely functional tree with arbitrarily many branches at each node. *)
|
2022-01-30 00:55:42 +00:00
|
|
|
type 'a tree =
|
|
|
|
| Leaf
|
|
|
|
| Branch of 'a * 'a tree list
|
|
|
|
|
|
|
|
(** Identity function. *)
|
|
|
|
val id : 'a -> 'a
|
|
|
|
|
|
|
|
(** Suppresses compiler warnings for unassigned return value from function. *)
|
|
|
|
val ignore : 'a -> unit
|
|
|
|
|
|
|
|
(** Function composition. (f >> g) x represents g (f x). *)
|
|
|
|
val ( >> ) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
|
|
|
|
|
|
|
|
(** Function composition. (f << g) x represents f (g x). *)
|
|
|
|
val ( << ) : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b
|
|
|
|
|
|
|
|
(** Pipeline operator, to reverse function application order. *)
|
|
|
|
val ( |> ) : 'a -> ('a -> 'b) -> 'b
|
|
|
|
|
|
|
|
(** Checks for structural equality. *)
|
2022-02-04 03:06:51 +00:00
|
|
|
external ( = ) : 'a -> 'a -> bool = "%equal"
|
2022-01-30 00:55:42 +00:00
|
|
|
|
|
|
|
(** Checks for structural inequality. *)
|
2022-02-04 03:06:51 +00:00
|
|
|
external ( <> ) : 'a -> 'a -> bool = "%notequal"
|
2022-01-30 00:55:42 +00:00
|
|
|
|
|
|
|
(** Polymorphic less than. *)
|
2022-02-04 03:06:51 +00:00
|
|
|
external ( < ) : 'a -> 'a -> bool = "%lessthan"
|
2022-01-30 00:55:42 +00:00
|
|
|
|
|
|
|
(** Polymorphic greater than. *)
|
2022-02-04 03:06:51 +00:00
|
|
|
external ( > ) : 'a -> 'a -> bool = "%greaterthan"
|
2022-01-30 00:55:42 +00:00
|
|
|
|
|
|
|
(** Polymorphic less than or equal to. *)
|
2022-02-04 03:06:51 +00:00
|
|
|
external ( <= ) : 'a -> 'a -> bool = "%lessequal"
|
2022-01-30 00:55:42 +00:00
|
|
|
|
|
|
|
(** Polymorphic greater than or equal to. *)
|
2022-02-04 03:06:51 +00:00
|
|
|
external ( >= ) : 'a -> 'a -> bool = "%greaterequal"
|
2022-01-30 00:55:42 +00:00
|
|
|
|
|
|
|
(** Logical negation. *)
|
|
|
|
val not : bool -> bool
|
|
|
|
|
|
|
|
(** Logical or (infix). *)
|
2022-02-04 03:06:51 +00:00
|
|
|
external ( or ) : bool -> bool -> bool = "%sequor"
|
2022-01-30 00:55:42 +00:00
|
|
|
|
|
|
|
(** Logical and. *)
|
2022-02-04 03:06:51 +00:00
|
|
|
external ( & ) : bool -> bool -> bool = "%sequand"
|
|
|
|
|
|
|
|
(** Reference cells for mutable variables. *)
|
|
|
|
type 'a ref = { mutable contents : 'a; }
|
|
|
|
|
|
|
|
(** Creates a reference cell. *)
|
|
|
|
val ref : 'a -> 'a ref
|
|
|
|
|
|
|
|
(** Updates a reference cell. *)
|
|
|
|
val ( := ) : 'a ref -> 'a -> unit
|
|
|
|
|
|
|
|
(** Returns the contents of a reference cell. *)
|
|
|
|
val ( ! ) : 'a ref -> 'a
|