1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889open!Importletinvalid_argf=Printf.invalid_argfmoduleT=structtypet=bool[@@deriving_inlinecompare,enumerate,hash,sexp,sexp_grammar]letcompare=(compare_bool:t->t->int)letall=([false;true]:tlist)let(hash_fold_t:Ppx_hash_lib.Std.Hash.state->t->Ppx_hash_lib.Std.Hash.state)=hash_fold_booland(hash:t->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=hash_boolinfunx->funcx;;lett_of_sexp=(bool_of_sexp:Sexplib0.Sexp.t->t)letsexp_of_t=(sexp_of_bool:t->Sexplib0.Sexp.t)let(t_sexp_grammar:tSexplib0.Sexp_grammar.t)=bool_sexp_grammar[@@@end]lethashable:tHashable.t={hash;compare;sexp_of_t}letof_string=function|"true"->true|"false"->false|s->invalid_argf"Bool.of_string: expected true or false but got %s"s();;letto_string=Caml.string_of_boolendincludeTincludeComparator.Make(T)includePretty_printer.Register(structtypenonrect=tletto_string=to_stringletmodule_name="Base.Bool"end)(* Open replace_polymorphic_compare after including functor instantiations so they do not
shadow its definitions. This is here so that efficient versions of the comparison
functions are available within this module. *)open!Bool_replace_polymorphic_compareletinvariant(_:t)=()letbetweent~low~high=low<=t&&t<=highletclamp_uncheckedt~min~max=ift<minthenminelseift<=maxthentelsemaxletclamp_exnt~min~max=assert(min<=max);clamp_uncheckedt~min~max;;letclampt~min~max=ifmin>maxthenOr_error.error_s(Sexp.message"clamp requires [min <= max]"["min",T.sexp_of_tmin;"max",T.sexp_of_tmax])elseOk(clamp_uncheckedt~min~max);;letto_intx=bool_to_intxmoduleNon_short_circuiting=struct(* We don't expose this, since we don't want to break the invariant mentioned below of
(to_int true = 1) and (to_int false = 0). *)letunsafe_of_int(x:int):bool=Caml.Obj.magicxlet(||)ab=unsafe_of_int(to_intalorto_intb)let(&&)ab=unsafe_of_int(to_intalandto_intb)end(* We do this as a direct assert on the theory that it's a cheap thing to test and a
really core invariant that we never expect to break, and we should be happy for a
program to fail immediately if this is violated. *)let()=assert(Poly.(=)(to_inttrue)1&&Poly.(=)(to_intfalse)0)(* Include type-specific [Replace_polymorphic_compare] at the end, after
including functor application that could shadow its definitions. This is
here so that efficient versions of the comparison functions are exported by
this module. *)includeBool_replace_polymorphic_compare