Skip to main content
Version: 2.5.x (dev)

Programming

error.on_error

Register a callback to monitor errors raised during the execution of the program. The callback is allow to re-raise a different error if needed. The callback passed to this function is called on every errors, not just uncaught errors.

Type:

(((error
.{
kind : string,
message : string,
trace : [
{
cstart : int,
cstop : int,
filename : string,
lstart : int,
lstop : int,
to_string : (?prefix : string) -> string
}]
}) -> unit)) -> unit

Arguments:

  • (unlabeled) (of type (error .{ kind : string, message : string, trace : [ { cstart : int, cstop : int, filename : string, lstart : int, lstop : int, to_string : (?prefix : string) -> string }] }) -> unit)

error.raise

Raise an error.

Type:

(error, ?string) -> 'a

Arguments:

  • (unlabeled) (of type error): Error kind.
  • (unlabeled) (of type string, which defaults to ""): Description of the error.

error.register

Register an error of the given kind

Type:

(string) -> error

Arguments:

  • (unlabeled) (of type string): Kind of the error

Methods:

  • kind (of type string): Error kind.
  • message (of type string): Error message.
  • trace (of type [ { cstart : int, cstop : int, filename : string, lstart : int, lstop : int, to_string : (?prefix : string) -> string }]): Error stacktrace.

fst

Get the first component of a pair.

Type:

(('a * 'b)) -> 'a

Arguments:

  • (unlabeled) (of type 'a * 'b)

ignore

Convert anything to unit, preventing warnings.

Type:

('a) -> unit

Arguments:

  • (unlabeled) (of type 'a)

null

Create a nullable value.

Type:

(?'a) -> 'a?

Arguments:

  • (unlabeled) (of type 'a, which defaults to null): Value to make nullable.

null.case

Return a result dending on whether a value is nothing or not.

Type:

('a?, (() -> 'b), (('a) -> 'b)) -> 'b

Arguments:

  • (unlabeled) (of type 'a?): Value to reason by case analysis on.
  • (unlabeled) (of type () -> 'b): Value to return in case we have nothing.
  • (unlabeled) (of type ('a) -> 'b): Value to return in case we have something.

null.default

Return a result dending on whether a value is nothing or not.

Type:

('a?, (() -> 'a)) -> 'a

Arguments:

  • (unlabeled) (of type 'a?): Value to reason by case analysis on.
  • (unlabeled) (of type () -> 'a): Value to return in case we have nothing.

position

Return the current position in the script

Type:

() -> unit

Methods:

  • cstart (of type int): Starting character
  • cstop (of type int): Stopping character
  • filename (of type string): Filename
  • lstart (of type int): Starting line
  • lstop (of type int): Stopping line
  • to_string (of type (?prefix : string) -> string): Render as string

print

Print on standard output.

Type:

(?newline : bool, 'a) -> unit

Arguments:

  • newline (of type bool, which defaults to true): If true, a newline is added after displaying the value.
  • (unlabeled) (of type 'a)

ref

Create a reference, i.e. a value which can be modified.

Type:

('a) -> () -> 'a

Arguments:

  • (unlabeled) (of type 'a)

Methods:

  • set (of type ('A) -> unit): Set the value of the reference.

snd

Get the second component of a pair.

Type:

(('a * 'b)) -> 'b

Arguments:

  • (unlabeled) (of type 'a * 'b)

sqlite

Manipulate an SQLITE database.

Type:

(string) -> unit

Arguments:

  • (unlabeled) (of type string): File where the data base is stored

Methods:

  • close (of type () -> unit): Close the database. It should not be accessed afterward.
  • exec (of type (string) -> unit): Execute an SQL operation.
  • insert (of type (table : string, ?replace : bool, 'A) -> unit where 'A is a record with int, float, string or null methods.): Insert a value represented as a record into a table.
  • iter (of type (((sqlite.row.{to_list : () -> [string * string?]}) -> unit), string) -> unit): Iterate a function over all the results of a query. Result can be parsed using let sqlite.row = ....
  • query (of type (string) -> [sqlite.row.{to_list : () -> [string * string?]}]): Execute an SQL operation returning the result. Result can be parsed using let sqlite.query = ....

sqlite.escape

Escape a string for use in a query.

Type:

(string) -> string

Arguments:

  • (unlabeled) (of type string): String to escape.

thread.delay

Delay the current thread by the given duration in seconds.

Type:

(float) -> unit

Arguments:

  • (unlabeled) (of type float)

thread.on_error

Register the function to be called when an error of the given kind is raised in a thread. Catches all errors if first argument is null.

Type:

(error?, ((backtrace : string, error) -> unit)) -> unit

Arguments:

  • (unlabeled) (of type error?)
  • (unlabeled) (of type (backtrace : string, error) -> unit)

thread.pause

Pause execution for a given amount of seconds. This puts the calling thread to sleep and should not be used in the main streaming loop.

Type:

(float) -> unit

Arguments:

  • (unlabeled) (of type float): Number of seconds of pause.

thread.run.recurrent

Run a recurrent function in a separate thread.

Type:

(?fast : bool, ?delay : float, ?on_error : ((error) -> float)?,
(() -> float)) -> unit

Arguments:

  • fast (of type bool, which defaults to true): Whether the thread is supposed to return quickly or not. Typically, blocking tasks (e.g. fetching data over the internet) should not be considered to be fast. When set to false its priority will be lowered below that of request resolutions and fast timeouts. This is only effective if you set a dedicated queue for fast tasks, see the "scheduler" settings for more details.
  • delay (of type float, which defaults to 0.0): Delay (in sec.) after which the thread should be launched.
  • on_error (of type ((error) -> float)?, which defaults to null): Error callback executed when an error occurred while running the given function. When passed, all raised errors are silenced unless re-raised by the callback.
  • (unlabeled) (of type () -> float): Function to execute recurrently. The returned value is the delay (in sec.) in which the function should be run again (it won't be run if the value is strictly negative).

while

A while loop.

Type:

({bool}, (() -> unit)) -> unit

Arguments:

  • (unlabeled) (of type {bool}): Condition guarding the loop.
  • (unlabeled) (of type () -> unit): Function to execute.