spotlib
Library
Module
Module type
Parameter
Class
Class type
include module type of struct include Base end
Common types
Result/Either monad using polymorphic variant. Obsolete. Use the primitive type result
instead.
Function compositions and other operators
Functional composition. Haskell's (.) Use power
if you want to use the original ( ** )
.
Functional composition in swapped order. Same as Haskell's (>>>)
Super flip
of Haskell. The first argument is labeled and becomes commutative.
Super flip
of Haskell. The first argument is labeled and becomes commutative.
Imperative operations
val with_ref : 'a -> ( 'a ref -> 'b ) -> 'a * 'b
val with_ref_ : 'a -> ( 'a ref -> unit ) -> 'a
with_ref
and with_ref_
runs a function with a reference with the specified initial value.
I/O
val with_oc : out_channel -> ( out_channel -> 'a ) -> 'a
val with_ic : in_channel -> ( in_channel -> 'a ) -> 'a
Misc things
val sprintf : ( 'a, unit, string ) format -> 'a
Printf.sprintf
is available without tying Printf.
val ksprintf : ( string -> 'a ) -> ( 'b, unit, string, 'a ) format4 -> 'b
Printf.ksprintf
is available without tying Printf.
val (!%) : ( 'a, unit, string ) format -> 'a
Printf.sprintf
, prefix style. Bought from ITPL.
val (!!%) : ( 'a, Format.formatter, unit ) format -> 'a
Format.eprintf
, prefix style.
val memoize_gen :
( ( 'a -> 'b ) -> 'a -> 'b ) ->
( 'a -> 'b ) * ( 'a, 'b ) Hashtbl.t
Generic memozation by hash with fixed point. You can call memoized self inside:
memoize_gen (fun self -> .... self v ....) f
Memozation by hash with fixed point. You can call memoized self inside:
memoize_rec (fun self -> .... self v ....) f
Simple profiling. Returns seconds. If f a
raises an exception e
, then time f a
raises e
too.
val (+=) : int ref -> int -> unit
val (-=) : int ref -> int -> unit
val find_by_iter :
( ( 'a -> unit ) -> 'collection -> unit ) ->
( 'a -> bool ) ->
'collection ->
'a option
find the first element where predicate
holds by iteration find_by_iter iterator predicate colleciton
find_in_tree get_subs p a
visits a
and finds the first sub node in which p
holds. get_subs
returns the sub nodes of a node.
Keep repeating a function until a final result is producted.
Comparison
compare_on f a b
compares a
and b
not by themselves but by f a
and f b
.
val add_if_not_mem : 'a -> 'a list ref -> [> `AlreadyIn | `NewlyAdded ]
add_if_not_mem
adds a
to asref
if not (List.mem a !asref)
then return `NewlyAdded
. Otherwise it returns `AlreadIn
and asref
is not modified.
String <-> bytes conversions
module Monad = Monad
module Option = Option
include module type of struct include Option.Stdlib end
val (//) : 'a Option.t -> 'a -> 'a
Same as default
but the default value is always evaluated
module Weaktbl = Weaktbl
module Hashset = Hashset
module File = File
module Comopt = Comopt
module Overload = Overload
module Mtypes = Mtypes
module Stream = SpotStream
module Poly_result = Poly_result
module Result = Vresult
include module type of struct include Result.Stdlib end
val ok : 'a -> ( 'a, 'error ) result
val ng : 'error -> ( 'a, 'error ) result
No Good
val from_Ok : ( 'a, 'error ) Result.t -> 'a
Raises IsError
when not Ok _
val result : ( 'a -> 'b ) -> ( 'c -> 'b ) -> ( 'a, 'c ) Result.t -> 'b
Haskell's either
val at_Error : ( 'err -> 'a ) -> ( 'a, 'err ) Result.t -> 'a
at_Error = result id
module Tuple = Tuple
include module type of struct include Tuple.Stdlib end
module Exn = Exn
include module type of struct include Exn.Stdlib end
Printf style errors
val failwithf : ( 'a, unit, string, 'b ) format4 -> 'a
val invalid_argf : ( 'a, unit, string, 'b ) format4 -> 'a
val raisef : ( string -> exn ) -> ( 'a, unit, string, 'b ) format4 -> 'a
Exception handling
It raises an exception Finally (org, final)
when finally
cannot recover the error.
It raises an exception Finally (org, final)
when finally
cannot recover the error.
val catch : ( 'a -> 'b ) -> 'a -> ( 'b, [> `Exn of exn ] ) result
val catch_ : ( unit -> 'b ) -> ( 'b, [> `Exn of exn ] ) result
tee f v ~handler
. If f v
raises an exception e
, handler e
is executed, then e
is reraised.
val with_return : ( 'a return -> 'a ) -> 'a
module Temporal = Temporal
module Year = Temporal.Year
module Date = Temporal.Date
module Time = Temporal.Time
module Datetime = Temporal.Datetime
module IntRange = IntRange
module List : sig ... end
include module type of struct include Xlist.Stdlib end
val (+::=) : 'a list ref -> 'a -> unit
Same as accum
module Array : sig ... end
module Format : sig ... end
module Hashtbl : sig ... end
module String : sig ... end
include module type of struct include Xstring.Stdlib end
module Bytes : sig ... end
module Lazy : sig ... end
module Filename : sig ... end
include module type of struct include Xfilename.Stdlib end
module Filepath = Filepath
module Unix : sig ... end
include module type of struct include Xunix.Stdlib end
module Printf : sig ... end
module Sys : sig ... end
module Set = Xset
module StringSet : sig ... end
module IntSet : sig ... end
module Int64 : sig ... end
module Printexc : sig ... end
module Obj : sig ... end
module URL = URL
module Gc : sig ... end
module UniqueID = UniqueID
module Once = Once
module Shell = Shell
module Lexing : sig ... end
module Command = Command