package eventually

All checked builds pass
  1. Overview
  2. Docs
Time-bounded computations and stream iteration

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.2.0.tar.gz
md5=2ff603e740d1267316d1dcf3ce4e0c39
sha512=48cf12103dd2f67ffdaf9ab4d061432ccbaf1e36c454f9928c76abde58abb02076fecdb23538a16480c8485e449ad424d2205913483392b99619b3ed1503db38

doc/README.html

OCaml-CI Build Status

Eventually

A small OCaml library for imposing logical time bounds on computations that may otherwise diverge.

Usage

dune build            # Build the library and executable
dune runtest          # Run tests
dune exec eventually  # Run a small demonstration

Examples

Time-bounded computation

An 'a Eventually.eventually is a computation subject to a logical time budget, which is consumed by way of Eventually.tick n.

let rec loop n =
  let* () = Eventually.tick 1 in  (* consume one tick *)
  Printf.printf "tick %d\n" n;    (* print "tick n" *)
  match n with
  | 0 -> Eventually.return "foo"  (* if `n=0` then return "foo" *)
  | _ -> loop (n - 1)             (* else decrement `n` and repeat *)

Timer.incr n Timer.zero supplies a budget of n ticks.

(* Prints "tick 3", "tick 2".
   Returns `Eventually.Timeout`. *)
let _ = Eventually.run (Timer.incr 2 Timer.zero) (loop 3)

(* Prints "tick 3", "tick 2", "tick 1", "tick 0".
   Returns `Eventually.Success "foo"`. *)
let _ = Eventually.run (Timer.incr 5 Timer.zero) (loop 3)

(* Prints "tick -4", "tick -5".
   Returns `Eventually.Timeout`. *)
let _ = Eventually.run (Timer.incr 2 Timer.zero) (loop -4)

Timer.forever supplies infinitely many ticks.

(* Prints "tick 3", "tick 2", "tick 1", "tick 0".
   Returns `Eventually.Success "foo"`. *)
let _ = Eventually.run (Timer.forever) (loop 3)

(* Prints "tick -4", "tick -5", "tick -6", "tick -7"...
   The computation diverges. *)
let _ = Eventually.run (Timer.forever) (loop -4)

Project layout

lib/   The Timer, Eventually, and Supply library modules
bin/   The Hailstone Sequence and Newton's Method demonstration executable
test/  Package tests