123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468(** This module is the toplevel of the Base library; it's what you get when you write
[open Base].
The goal of Base is both to be a more complete standard library, with richer APIs,
and to be more consistent in its design. For instance, in the standard library
some things have modules and others don't; in Base, everything is a module.
Base extends some modules and data structures from the standard library, like [Array],
[Buffer], [Bytes], [Char], [Hashtbl], [Int32], [Int64], [Lazy], [List], [Map],
[Nativeint], [Printf], [Random], [Set], [String], [Sys], and [Uchar]. One key
difference is that Base doesn't use exceptions as much as the standard library and
instead makes heavy use of the [Result] type, as in:
{[ type ('a,'b) result = Ok of 'a | Error of 'b ]}
Base also adds entirely new modules, most notably:
- [Comparable], [Comparator], and [Comparisons] in lieu of polymorphic compare.
- [Container], which provides a consistent interface across container-like data
structures (arrays, lists, strings).
- [Result], [Error], and [Or_error], supporting the or-error pattern.
The recommended way to use Base is to build with [-open Base]. Files compiled this
way will have the environment described in this file as their initial environment.
*)(*_ We hide this from the web docs because the line wrapping is bad, making it
pretty much inscrutable. *)(**/**)(* The intent is to shadow all of INRIA's standard library. Modules below would cause
compilation errors without being removed from [Shadow_stdlib] before inclusion. *)include(Shadow_stdlib:moduletypeofstructincludeShadow_stdlibend(* Modules defined in Base *)withmoduleArray:=Shadow_stdlib.ArraywithmoduleBool:=Shadow_stdlib.BoolwithmoduleBuffer:=Shadow_stdlib.BufferwithmoduleBytes:=Shadow_stdlib.ByteswithmoduleChar:=Shadow_stdlib.CharwithmoduleFloat:=Shadow_stdlib.FloatwithmoduleHashtbl:=Shadow_stdlib.HashtblwithmoduleInt:=Shadow_stdlib.IntwithmoduleInt32:=Shadow_stdlib.Int32withmoduleInt64:=Shadow_stdlib.Int64withmoduleLazy:=Shadow_stdlib.LazywithmoduleList:=Shadow_stdlib.ListwithmoduleMap:=Shadow_stdlib.MapwithmoduleNativeint:=Shadow_stdlib.NativeintwithmoduleOption:=Shadow_stdlib.OptionwithmodulePrintf:=Shadow_stdlib.PrintfwithmoduleQueue:=Shadow_stdlib.QueuewithmoduleRandom:=Shadow_stdlib.RandomwithmoduleResult:=Shadow_stdlib.ResultwithmoduleSet:=Shadow_stdlib.SetwithmoduleStack:=Shadow_stdlib.StackwithmoduleString:=Shadow_stdlib.StringwithmoduleSys:=Shadow_stdlib.SyswithmoduleUchar:=Shadow_stdlib.UcharwithmoduleUnit:=Shadow_stdlib.Unit(* Support for generated lexers *)withmoduleLexing:=Shadow_stdlib.Lexingwithtype('a,'b,'c)format:=('a,'b,'c)formatwithtype('a,'b,'c,'d)format4:=('a,'b,'c,'d)format4withtype('a,'b,'c,'d,'e,'f)format6:=('a,'b,'c,'d,'e,'f)format6withtype'aref:='aref)[@ocaml.warning"-3"](**/**)open!ImportmoduleApplicative=ApplicativemoduleArray=ArraymoduleAvltree=AvltreemoduleBacktrace=BacktracemoduleBinary_search=Binary_searchmoduleBinary_searchable=Binary_searchablemoduleBlit=BlitmoduleBool=BoolmoduleBuffer=BuffermoduleBytes=BytesmoduleChar=CharmoduleComparable=ComparablemoduleComparator=ComparatormoduleComparisons=ComparisonsmoduleContainer=ContainermoduleEither=EithermoduleEqual=EqualmoduleError=ErrormoduleExn=ExnmoduleField=FieldmoduleFloat=FloatmoduleFloatable=FloatablemoduleFn=FnmoduleFormatter=FormattermoduleHash=HashmoduleHash_set=Hash_setmoduleHashable=HashablemoduleHasher=HashermoduleHashtbl=HashtblmoduleIdentifiable=IdentifiablemoduleIndexed_container=Indexed_containermoduleInfo=InfomoduleInt=IntmoduleInt_conversions=Int_conversionsmoduleInt32=Int32moduleInt63=Int63moduleInt64=Int64moduleIntable=IntablemoduleInt_math=Int_mathmoduleInvariant=InvariantmoduleLazy=LazymoduleList=ListmoduleMap=MapmoduleMaybe_bound=Maybe_boundmoduleMonad=MonadmoduleNativeint=NativeintmoduleOption=OptionmoduleOption_array=Option_arraymoduleOr_error=Or_errormoduleOrdered_collection_common=Ordered_collection_commonmoduleOrdering=OrderingmodulePoly=PolymodulePolymorphic_compare=Poly[@@deprecated"[since 2018-11] use [Poly] instead"]modulePopcount=Popcount[@@deprecated"[since 2018-10] use [popcount] functions in the individual int modules"]modulePretty_printer=Pretty_printermodulePrintf=PrintfmoduleLinked_queue=Linked_queuemoduleQueue=QueuemoduleRandom=RandommoduleRef=RefmoduleResult=ResultmoduleSequence=SequencemoduleSet=SetmoduleSexpable=SexpablemoduleSign=SignmoduleSign_or_nan=Sign_or_nanmoduleSource_code_position=Source_code_positionmoduleStack=StackmoduleStaged=StagedmoduleString=StringmoduleStringable=StringablemoduleSys=SysmoduleT=TmoduleType_equal=Type_equalmoduleUniform_array=Uniform_arraymoduleUnit=UnitmoduleUchar=UcharmoduleValidate=ValidatemoduleVariant=VariantmoduleWith_return=With_returnmoduleWord_size=Word_size(* Avoid a level of indirection for uses of the signatures defined in [T]. *)includeT(* This is a hack so that odoc creates better documentation. *)moduleSexp=structincludeSexp_with_comparable(** @inline *)end(**/**)moduleExported_for_specific_uses=structmoduleFieldslib=FieldslibmodulePpx_hash_lib=Ppx_hash_libmoduleSexplib=SexplibmoduleVariantslib=VariantslibmodulePpx_compare_lib=Ppx_compare_libmodulePpx_sexp_conv_lib=Ppx_sexp_conv_libletam_testing=am_testingend(**/**)moduleExport=struct(* [deriving hash] is missing for [array] and [ref] since these types are mutable. *)type'aarray='aArray.t[@@deriving_inlinecompare,equal,sexp]letcompare_array:'a.('a->'a->int)->'aarray->'aarray->int=Array.compareletequal_array:'a.('a->'a->bool)->'aarray->'aarray->bool=Array.equalletarray_of_sexp:'a.(Ppx_sexp_conv_lib.Sexp.t->'a)->Ppx_sexp_conv_lib.Sexp.t->'aarray=Array.t_of_sexpletsexp_of_array:'a.('a->Ppx_sexp_conv_lib.Sexp.t)->'aarray->Ppx_sexp_conv_lib.Sexp.t=Array.sexp_of_t[@@@end]typebool=Bool.t[@@deriving_inlinecompare,equal,hash,sexp]letcompare_bool=(Bool.compare:bool->bool->int)letequal_bool=(Bool.equal:bool->bool->bool)let(hash_fold_bool:Ppx_hash_lib.Std.Hash.state->bool->Ppx_hash_lib.Std.Hash.state)=Bool.hash_fold_tand(hash_bool:bool->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=Bool.hashinfunx->funcxletbool_of_sexp=(Bool.t_of_sexp:Ppx_sexp_conv_lib.Sexp.t->bool)letsexp_of_bool=(Bool.sexp_of_t:bool->Ppx_sexp_conv_lib.Sexp.t)[@@@end]typechar=Char.t[@@deriving_inlinecompare,equal,hash,sexp]letcompare_char=(Char.compare:char->char->int)letequal_char=(Char.equal:char->char->bool)let(hash_fold_char:Ppx_hash_lib.Std.Hash.state->char->Ppx_hash_lib.Std.Hash.state)=Char.hash_fold_tand(hash_char:char->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=Char.hashinfunx->funcxletchar_of_sexp=(Char.t_of_sexp:Ppx_sexp_conv_lib.Sexp.t->char)letsexp_of_char=(Char.sexp_of_t:char->Ppx_sexp_conv_lib.Sexp.t)[@@@end]typeexn=Exn.t[@@deriving_inlinesexp_of]letsexp_of_exn=(Exn.sexp_of_t:exn->Ppx_sexp_conv_lib.Sexp.t)[@@@end]typefloat=Float.t[@@deriving_inlinecompare,equal,hash,sexp]letcompare_float=(Float.compare:float->float->int)letequal_float=(Float.equal:float->float->bool)let(hash_fold_float:Ppx_hash_lib.Std.Hash.state->float->Ppx_hash_lib.Std.Hash.state)=Float.hash_fold_tand(hash_float:float->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=Float.hashinfunx->funcxletfloat_of_sexp=(Float.t_of_sexp:Ppx_sexp_conv_lib.Sexp.t->float)letsexp_of_float=(Float.sexp_of_t:float->Ppx_sexp_conv_lib.Sexp.t)[@@@end]typeint=Int.t[@@deriving_inlinecompare,equal,hash,sexp]letcompare_int=(Int.compare:int->int->int)letequal_int=(Int.equal:int->int->bool)let(hash_fold_int:Ppx_hash_lib.Std.Hash.state->int->Ppx_hash_lib.Std.Hash.state)=Int.hash_fold_tand(hash_int:int->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=Int.hashinfunx->funcxletint_of_sexp=(Int.t_of_sexp:Ppx_sexp_conv_lib.Sexp.t->int)letsexp_of_int=(Int.sexp_of_t:int->Ppx_sexp_conv_lib.Sexp.t)[@@@end]typeint32=Int32.t[@@deriving_inlinecompare,equal,hash,sexp]letcompare_int32=(Int32.compare:int32->int32->int)letequal_int32=(Int32.equal:int32->int32->bool)let(hash_fold_int32:Ppx_hash_lib.Std.Hash.state->int32->Ppx_hash_lib.Std.Hash.state)=Int32.hash_fold_tand(hash_int32:int32->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=Int32.hashinfunx->funcxletint32_of_sexp=(Int32.t_of_sexp:Ppx_sexp_conv_lib.Sexp.t->int32)letsexp_of_int32=(Int32.sexp_of_t:int32->Ppx_sexp_conv_lib.Sexp.t)[@@@end]typeint64=Int64.t[@@deriving_inlinecompare,equal,hash,sexp]letcompare_int64=(Int64.compare:int64->int64->int)letequal_int64=(Int64.equal:int64->int64->bool)let(hash_fold_int64:Ppx_hash_lib.Std.Hash.state->int64->Ppx_hash_lib.Std.Hash.state)=Int64.hash_fold_tand(hash_int64:int64->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=Int64.hashinfunx->funcxletint64_of_sexp=(Int64.t_of_sexp:Ppx_sexp_conv_lib.Sexp.t->int64)letsexp_of_int64=(Int64.sexp_of_t:int64->Ppx_sexp_conv_lib.Sexp.t)[@@@end]type'alist='aList.t[@@deriving_inlinecompare,equal,hash,sexp]letcompare_list:'a.('a->'a->int)->'alist->'alist->int=List.compareletequal_list:'a.('a->'a->bool)->'alist->'alist->bool=List.equallethash_fold_list:'a.(Ppx_hash_lib.Std.Hash.state->'a->Ppx_hash_lib.Std.Hash.state)->Ppx_hash_lib.Std.Hash.state->'alist->Ppx_hash_lib.Std.Hash.state=List.hash_fold_tletlist_of_sexp:'a.(Ppx_sexp_conv_lib.Sexp.t->'a)->Ppx_sexp_conv_lib.Sexp.t->'alist=List.t_of_sexpletsexp_of_list:'a.('a->Ppx_sexp_conv_lib.Sexp.t)->'alist->Ppx_sexp_conv_lib.Sexp.t=List.sexp_of_t[@@@end]typenativeint=Nativeint.t[@@deriving_inlinecompare,equal,hash,sexp]letcompare_nativeint=(Nativeint.compare:nativeint->nativeint->int)letequal_nativeint=(Nativeint.equal:nativeint->nativeint->bool)let(hash_fold_nativeint:Ppx_hash_lib.Std.Hash.state->nativeint->Ppx_hash_lib.Std.Hash.state)=Nativeint.hash_fold_tand(hash_nativeint:nativeint->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=Nativeint.hashinfunx->funcxletnativeint_of_sexp=(Nativeint.t_of_sexp:Ppx_sexp_conv_lib.Sexp.t->nativeint)letsexp_of_nativeint=(Nativeint.sexp_of_t:nativeint->Ppx_sexp_conv_lib.Sexp.t)[@@@end]type'aoption='aOption.t[@@deriving_inlinecompare,equal,hash,sexp]letcompare_option:'a.('a->'a->int)->'aoption->'aoption->int=Option.compareletequal_option:'a.('a->'a->bool)->'aoption->'aoption->bool=Option.equallethash_fold_option:'a.(Ppx_hash_lib.Std.Hash.state->'a->Ppx_hash_lib.Std.Hash.state)->Ppx_hash_lib.Std.Hash.state->'aoption->Ppx_hash_lib.Std.Hash.state=Option.hash_fold_tletoption_of_sexp:'a.(Ppx_sexp_conv_lib.Sexp.t->'a)->Ppx_sexp_conv_lib.Sexp.t->'aoption=Option.t_of_sexpletsexp_of_option:'a.('a->Ppx_sexp_conv_lib.Sexp.t)->'aoption->Ppx_sexp_conv_lib.Sexp.t=Option.sexp_of_t[@@@end]type'aref='aRef.t[@@deriving_inlinecompare,equal,sexp]letcompare_ref:'a.('a->'a->int)->'aref->'aref->int=Ref.compareletequal_ref:'a.('a->'a->bool)->'aref->'aref->bool=Ref.equalletref_of_sexp:'a.(Ppx_sexp_conv_lib.Sexp.t->'a)->Ppx_sexp_conv_lib.Sexp.t->'aref=Ref.t_of_sexpletsexp_of_ref:'a.('a->Ppx_sexp_conv_lib.Sexp.t)->'aref->Ppx_sexp_conv_lib.Sexp.t=Ref.sexp_of_t[@@@end]typestring=String.t[@@deriving_inlinecompare,equal,hash,sexp]letcompare_string=(String.compare:string->string->int)letequal_string=(String.equal:string->string->bool)let(hash_fold_string:Ppx_hash_lib.Std.Hash.state->string->Ppx_hash_lib.Std.Hash.state)=String.hash_fold_tand(hash_string:string->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=String.hashinfunx->funcxletstring_of_sexp=(String.t_of_sexp:Ppx_sexp_conv_lib.Sexp.t->string)letsexp_of_string=(String.sexp_of_t:string->Ppx_sexp_conv_lib.Sexp.t)[@@@end]typebytes=Bytes.t[@@deriving_inlinecompare,equal,sexp]letcompare_bytes=(Bytes.compare:bytes->bytes->int)letequal_bytes=(Bytes.equal:bytes->bytes->bool)letbytes_of_sexp=(Bytes.t_of_sexp:Ppx_sexp_conv_lib.Sexp.t->bytes)letsexp_of_bytes=(Bytes.sexp_of_t:bytes->Ppx_sexp_conv_lib.Sexp.t)[@@@end]typeunit=Unit.t[@@deriving_inlinecompare,equal,hash,sexp]letcompare_unit=(Unit.compare:unit->unit->int)letequal_unit=(Unit.equal:unit->unit->bool)let(hash_fold_unit:Ppx_hash_lib.Std.Hash.state->unit->Ppx_hash_lib.Std.Hash.state)=Unit.hash_fold_tand(hash_unit:unit->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=Unit.hashinfunx->funcxletunit_of_sexp=(Unit.t_of_sexp:Ppx_sexp_conv_lib.Sexp.t->unit)letsexp_of_unit=(Unit.sexp_of_t:unit->Ppx_sexp_conv_lib.Sexp.t)[@@@end](** Format stuff *)typenonrec('a,'b,'c)format=('a,'b,'c)formattypenonrec('a,'b,'c,'d)format4=('a,'b,'c,'d)format4typenonrec('a,'b,'c,'d,'e,'f)format6=('a,'b,'c,'d,'e,'f)format6(** {2 Sexp}
Exporting the ad-hoc types that are recognized by [ppx_sexp_*] converters.
[sexp_array], [sexp_list], and [sexp_option] allow a record field to be absent when
converting from a sexp, and if absent, the field will take a default value of the
appropriate type:
{v
sexp_array [||]
sexp_bool false
sexp_list []
sexp_option None
v}
[sexp_opaque] causes the conversion to sexp to produce the atom [<opaque>].
For more documentation, see sexplib/README.md. *)type'asexp_array='aarray[@@deprecated"[since 2019-03] use [@sexp.array] instead"]type'asexp_list='alist[@@deprecated"[since 2019-03] use [@sexp.list] instead"]type'asexp_opaque='a[@@deprecated"[since 2019-03] use [@sexp.opaque] instead"]type'asexp_option='aoption[@@deprecated"[since 2019-03] use [@sexp.option] instead"](** List operators *)includeList.Infix(** Int operators and comparisons *)includeInt.OincludeInt_replace_polymorphic_compare(** Float operators *)includeFloat.O_dot(* This is declared as an external to be optimized away in more contexts. *)(** Reverse application operator. [x |> g |> f] is equivalent to [f (g (x))]. *)external(|>):'a->('a->'b)->'b="%revapply"(** Application operator. [g @@ f @@ x] is equivalent to [g (f (x))]. *)external(@@):('a->'b)->'a->'b="%apply"(** Boolean operations *)(* These need to be declared as an external to get the lazy behavior *)external(&&):bool->bool->bool="%sequand"external(||):bool->bool->bool="%sequor"externalnot:bool->bool="%boolnot"(* This must be declared as an external for the warnings to work properly. *)externalignore:_->unit="%ignore"(** Common string operations *)let(^)=String.(^)(** Reference operations *)(* Declared as an externals so that the compiler skips the caml_modify when possible and
to keep reference unboxing working *)external(!):'aref->'a="%field0"externalref:'a->'aref="%makemutable"external(:=):'aref->'a->unit="%setfield0"(** Pair operations *)letfst=fstletsnd=snd(** Exceptions stuff *)(* Declared as an external so that the compiler may rewrite '%raise' as '%reraise'. *)externalraise:exn->_="%raise"letfailwith=failwithletinvalid_arg=invalid_argletraise_s=Error.raise_s(** Misc *)letphys_equal=phys_equalexternalforce:'aLazy.t->'a="%lazy_force"endincludeExportincludeContainer_intf.Export(** @inline *)exceptionNot_found_s=Not_found_s(* We perform these side effects here because we want them to run for any code that uses
[Base]. If this were in another module in [Base] that was not used in some program,
then the side effects might not be run in that program. This will run as long as the
program refers to at least one value directly in [Base]; referring to values in
[Base.Bool], for example, is not sufficient. *)let()=Backtrace.initialize_module()