123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125(*
* BatBool - Extended booleans
* Copyright (C) 2007 Bluestorm <bluestorm dot dylc on-the-server gmail dot com>
* 2008 David Teller
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version,
* with the special exception on linking described in file LICENSE.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)moduleBaseBool:BatNumber.NUMERIC_BASEwithtypet=bool=structtypet=boolexternalnot:bool ->bool="%boolnot"(** The boolean negation. *)external(&&):bool->bool->bool="%sequand"(** The boolean ``and''. Evaluation is sequential, left-to-right:
in [e1 && e2], [e1] is evaluated first, and if it returns [false],
[e2] is not evaluated at all. *)external(||):bool->bool->bool="%sequor"(** The boolean ``or''. Evaluation is sequential, left-to-right:
in [e1 || e2], [e1] is evaluated first, and if it returns [true],
[e2] is not evaluated at all. *)letzero,one=false,trueletneg=notletsucc_=trueletpred_=falseletabsx=xletadd=(||)letmul =(&&)letsub _=not(*Weird extrapolation*)letdiv__=invalid_arg"Bool.div"letmodulo__=invalid_arg"Bool.modulo"letpow__=invalid_arg"Bool.pow"letcompare=compareletof_int=function|0-> false|_->trueletto_int=function|false ->0|true->1letof_floatx=of_int(int_of_floatx)letto_floatx=float_of_int(to_intx)letof_string =function|"true" |"tt"|"1"->true|"false"|"ff"|"0"->false|_->invalid_arg"Bool.of_string"letto_string=string_of_boolendincludeBatNumber.MakeNumeric(BaseBool)(*$T succ
succ true = true
succ false = true
*)(*$T pred
pred true = false
pred false = false
*)(*$T abs
abs true = true
abs false = false
*)(*$T sub
sub true true = false
sub true false = true
sub false true = false
sub false false = true
*)(*$Q of_int
(Q.int) (fun i -> (of_int i) = (Int.(<>) i 0))
*)(*$T of_int
of_int 0 = false
*)(*$T
of_float (-1.) = true
of_float 0. = false
of_float nan = false
to_float true = 1.
to_float false = 0.
of_string "true" = true
of_string "false" = false
try ignore (of_string "smurf"); false with Invalid_argument _ -> true
*)externalnot:bool->bool="%boolnot"external(&&):bool->bool->bool="%sequand"external(||):bool->bool->bool="%sequor"typebounded=tletmin_num,max_num=false,trueletprint outt=BatInnerIO.nwriteout(to_stringt)(*$T
BatIO.to_string print true = "true"
BatIO.to_string print false = "false"
*)