diff --git a/src/core/CCBool.ml b/src/core/CCBool.ml index d19e86d1..227bc3b2 100644 --- a/src/core/CCBool.ml +++ b/src/core/CCBool.ml @@ -1,4 +1,3 @@ - (* This file is free software, part of containers. See file "license" for more details. *) open CCShims_ @@ -9,6 +8,23 @@ let equal (a:bool) b = Stdlib.(=) a b let compare (a:bool) b = Stdlib.compare a b +let to_int (x:bool) : int = if x then 1 else 0 + +(*$= + 1 (to_int true) + 0 (to_int false) +*) + +let of_int x : t = x<>0 + +(*$= + true (of_int 1) + false (of_int 0) + true (of_int 42) + true (of_int max_int) + true (of_int min_int) +*) + let negate = not type 'a printer = Format.formatter -> 'a -> unit diff --git a/src/core/CCBool.mli b/src/core/CCBool.mli index 3ba02bb2..a454552a 100644 --- a/src/core/CCBool.mli +++ b/src/core/CCBool.mli @@ -1,4 +1,3 @@ - (* This file is free software, part of containers. See file "license" for more details. *) (** {1 Basic Bool functions} *) @@ -10,6 +9,14 @@ val compare : t -> t -> int val equal : t -> t -> bool +val to_int : t -> int +(** [to_int true = 1], [to_int false = 0]. + @since NEXT_RELEASE *) + +val of_int : int -> t +(** [of_int i] is the same as [i <> 0] + @since NEXT_RELEASE *) + val negate : t -> t (** Negation on booleans (functional version of [not]). @deprecated since 1.3, simply use {!not} instead. *)