package odds

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Odds (Ocaml Dice Dice Something) is a library for rolling dice. It embeds the dice algebra into OCaml by providing dice rolling functions and lifting integer operations.

type 'a t

The type of dice expressions.

val die : int -> int t

die s is an expression for rolling one die of s sides: `1ds`.

Raises Invalid_argument if s is negative.

val dice : int -> int -> int t

dice n s is an expression for rolling n dice of s sides: `nds`.

Raises Invalid_argument if s is negative or if n is negative.

val inject : 'a -> 'a t

inject x is the trivial expression that always rolls to x.

val roll : ?state:Random.State.t -> 'a t -> 'a

roll ?state t is the result of the expression t. If the state is given, it is used as a seed to roll all the dice in order. Otherwise, a state is created for the formula.

May raise Invalid_argument if any subexpression does.

val roll_fold : ?state:Random.State.t -> folder:('acc -> int -> int -> 'acc) -> init:'acc -> 'a t -> 'a * 'acc

roll_fold ?state ~folder ~init t is similar to roll ?state t except that: the function folder is called on each dice roll. Specifically, folder acc s r is called where acc is the latest accumulator, s is the number of sides of the rolled dice, and r is the result.

May raise Invalid_argument if any subexpression does.

val lift1 : ('a -> 'b) -> 'a t -> 'b t
val lift2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
module Monad : sig ... end

The Monad module provides a monad to express dice formulas.

module Algebra : sig ... end

The Algebra module lifts most of the integer-related functions of the Pervasives module to apply to dice expressions.

module Comparisons : sig ... end
OCaml

Innovation. Community. Security.