1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495(*
* Copyright (C) 2012 Batteries Included Development Team
*
* 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
*)(* Inner functions for Pervasives, that can be accessed from other
modules without pulling in all of batteries as deps. *)letfinallyhandlerfx=letr=(tryfxwithe->handler();raisee)inhandler();rletwith_dispose~dispose fx=finally(fun()->disposex)fx(* unique int generation*)letunique_value=ref0letlock=ref BatConcurrent.nolockletunique()=BatConcurrent.sync!lockBatRef.post_incrunique_value(*$Q unique
Q.unit (fun () -> unique () <> unique ())
*)type('a,'b)result=##V>=4.8##('a,'b)Stdlib.result=|Okof'a|Error of'b(* Ideas taken from Nicholas Pouillard's my_std.ml in ocamlbuild/ *)letignore_ok=functionOk_-> ()|Errorex->raiseexletok=functionOkv-> v|Errorex->raiseexletwrapfx=tryOk (fx)withex->Errorexletforeverfx=ignore(whiletruedoignore(fx)done)letignore_exceptionsfx=tryignore(fx)with_->()(** {1 Operators}*)##V<4##let(|>)xf=fx##V>=4##external(|>):'a->('a->'b)->'b="%revapply"##V<4##let(@@)fx=fx##V>=4##external(@@):('a->'b)->'a->'b="%apply"let(%>)fgx=g(fx)let(%)fgx=f(gx)letflipfxy=fyxletcurryfxy=f(x,y)letuncurryf(x,y)=fxyletconstx_=xletnegpx=not(px)letneg2pxy=not(pxy)externalidentity:'a->'a="%identity"lettapfx=fx;xlet(|?)=BatOption.Infix.(|?)