Pretty much what the title says. Working on a standard library overlay, mainly for personal use, that tries to eliminate failure cases as much as possible. In addition to preferring options or results over exceptions, it also tries to define types that make failure cases impossible (e.g. non-empty lists), so it pushes the responsibility for error handling more in the direction of the input than the output (where results and options push it to the output).
One of the things that has always driven me crazy, not only about OCaml, but about programming in general is that integer division is not total. This shall not stand! We have the power! So I made a non-zero integer type and shadowed the division and modulo operators to only accept non-zero as a divisor. Is this nuts? Am I going to far? I just really like total functions.
type non_zero = private int
(** [non_zero] exists to make integer division total. You must convert
[int] to [non_zero] before you divide with [/] or [mod]. In this way, we
ensure division can never fail. *)
val nz : int -> non_zero option
(** ensure an integer is non-zero. total. *)
val nz_exn : int -> non_zero
(** ensure an integer is non-zero or raise an exception. *)
external unsafe_nz : int -> non_zero = "%identity"
(** "trust me that this integer cannot be zero" handle with care. *)
external nz_of_pos : Pos.t -> non_zero = "%identity"
(** If you're already dealing with a positive integer, we know it is not zero.
total. *)
external int_of_nz : non_zero -> int = "%identity"
(** when you need the underlying [int] from [nz]. total. *)
external ( / ) : int -> non_zero -> int = "%divint"
(** shadows [Stdlib.( / )]. total. *)
external ( mod ) : int -> non_zero -> int = "%modint"
(** shadows [Stdlib.( mod )]. total. *)