package spotlib

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Spotlib.SpotSource

include module type of struct include Base end
Common types
Sourcetype ('a, 'b) poly_result = [
  1. | `Ok of 'a
  2. | `Error of 'b
]

Result/Either monad using polymorphic variant. Obsolete. Use the primitive type result instead.

Function compositions and other operators
Sourceval (**) : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c

Functional composition. Haskell's (.) Use power if you want to use the original ( ** ).

Sourceval (*<) : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c

Same as ( ** ).

Sourceval (*>) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c

Functional composition in swapped order. Same as Haskell's (>>>)

Sourceval power : float -> float -> float

Replacement of ( ** )

Sourceval (&) : ('a -> 'b) -> 'a -> 'b

Haskell's ($).

Sourceval (&~) : (f:'a -> 'b) -> 'a -> 'b

Haskell's ($), with label 'f'.

Sourceval id : 'a -> 'a
Sourceval (|-) : 'a -> ('a -> unit) -> 'a

"tee". v |-- f is v but f v is run before v is returned

Sourceval flip : ('a -> 'b -> 'c) -> 'b -> 'a -> 'c

flip of Haskell

Sourceval (~~) : ('a -> 'b) -> f:'a -> 'b

Super flip of Haskell. The first argument is labeled and becomes commutative.

Sourceval flipf : ('a -> 'b) -> f:'a -> 'b

Super flip of Haskell. The first argument is labeled and becomes commutative.

Sourceval flip2 : ('a -> 'b -> 'c -> 'd) -> 'b -> 'c -> 'a -> 'd

flip f x2 x3 x1 = f x1 x2 x3

Imperative operations
Sourceval with_ref : 'a -> ('a ref -> 'b) -> 'a * 'b
Sourceval 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
Sourceval with_oc : out_channel -> (out_channel -> 'a) -> 'a
Sourceval with_ic : in_channel -> (in_channel -> 'a) -> 'a
Misc things
Sourceval sprintf : ('a, unit, string) format -> 'a

Printf.sprintf is available without tying Printf.

Sourceval ksprintf : (string -> 'a) -> ('b, unit, string, 'a) format4 -> 'b

Printf.ksprintf is available without tying Printf.

Sourceval (!%) : ('a, unit, string) format -> 'a

Printf.sprintf, prefix style. Bought from ITPL.

Sourceval (!!%) : ('a, Format.formatter, unit) format -> 'a

Format.eprintf, prefix style.

Sourceval 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

Sourceval memoize : ('c -> 'd) -> 'c -> 'd

Memozation by hash

Sourceval memoize_rec : (('a -> 'b) -> 'a -> 'b) -> 'a -> 'b

Memozation by hash with fixed point. You can call memoized self inside:

memoize_rec (fun self -> .... self v ....) f

Sourceval time : ('a -> 'b) -> 'a -> 'b * float

Simple profiling. Returns seconds. If f a raises an exception e, then time f a raises e too.

Sourceval (+=) : int ref -> int -> unit
Sourceval (-=) : int ref -> int -> unit
Sourceval 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

Sourceval find_in_tree : ('a -> 'a list) -> ('a -> 'res option) -> 'a -> 'res option

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.

Sourceval loop : ('a -> [< `Continue of 'a | `Break of 'b ]) -> 'a -> 'b

Keep repeating a function until a final result is producted.

Comparison
Sourceval compare_on : ('a -> 'b) -> 'a -> 'a -> int

compare_on f a b compares a and b not by themselves but by f a and f b.

Sourceval rev_compare_on : ('a -> 'b) -> 'a -> 'a -> int

rev_compare_on f a b = - (compare_on f a b)

Sourceval 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

Sourceval (!<$) : string -> bytes
Sourceval (!>$) : bytes -> string
Sourcemodule Monad = Monad
Sourcemodule Option = Option
include module type of struct include Option.Stdlib end
Sourceval from_Some : 'a option -> 'a

may raise Invalid_argument

Sourceval (//) : 'a Option.t -> 'a -> 'a

Same as default but the default value is always evaluated

Sourcemodule Weaktbl = Weaktbl
Sourcemodule Hashset = Hashset
Sourcemodule File = File
Sourcemodule Comopt = Comopt
Sourcemodule Overload = Overload
Sourcemodule Mtypes = Mtypes
Sourcemodule Stream = SpotStream
Sourcemodule Poly_result = Poly_result
Sourcemodule Result = Vresult
include module type of struct include Result.Stdlib end
Sourceval ok : 'a -> ('a, 'error) result
Sourceval ng : 'error -> ('a, 'error) result

No Good

Sourceval from_Ok : ('a, 'error) Vresult.t -> 'a

Raises IsError when not Ok _

Sourceval result : ('a -> 'b) -> ('c -> 'b) -> ('a, 'c) Vresult.t -> 'b

Haskell's either

Sourceval at_Error : ('err -> 'a) -> ('a, 'err) Vresult.t -> 'a

at_Error = result id

Sourcemodule Tuple = Tuple
include module type of struct include Tuple.Stdlib end
Sourceval map_fst : ('a -> 'b) -> ('a * 'c) -> 'b * 'c
Sourceval map_snd : ('a -> 'b) -> ('c * 'a) -> 'c * 'b
Sourcemodule Exn = Exn
include module type of struct include Exn.Stdlib end
Printf style errors
Sourceval failwithf : ('a, unit, string, 'b) format4 -> 'a
Sourceval invalid_argf : ('a, unit, string, 'b) format4 -> 'a
Sourceval raisef : (string -> exn) -> ('a, unit, string, 'b) format4 -> 'a
Exception handling
Sourceexception Finally of exn * exn
Sourceval protect : ('a -> 'b) -> 'a -> finally:('a -> unit) -> 'b

It raises an exception Finally (org, final) when finally cannot recover the error.

Sourceval protect_with : ('a -> 'b) -> 'a -> finally:('a -> 'c) -> 'b * 'c

It raises an exception Finally (org, final) when finally cannot recover the error.

Sourceval catch : ('a -> 'b) -> 'a -> ('b, [> `Exn of exn ]) result
Sourceval try_ignore : ('a -> unit) -> 'a -> unit
Sourceval try_or : ('a -> 'b) -> ('a -> 'b) -> 'a -> 'b
Sourceval try_bool : ('a -> unit) -> 'a -> bool

true at success

Sourceval protect_ : (unit -> 'b) -> finally:(unit -> unit) -> 'b
Sourceval protect_with_ : (unit -> 'b) -> finally:(unit -> 'c) -> 'b * 'c
Sourceval catch_ : (unit -> 'b) -> ('b, [> `Exn of exn ]) result
Sourceval try_ignore_ : (unit -> unit) -> unit
Sourceval try_or_ : (unit -> 'b) -> (unit -> 'b) -> 'b
Sourceval try_bool_ : (unit -> unit) -> bool
Sourceval tee : ('a -> 'b) -> 'a -> handler:(exn -> unit) -> 'b

tee f v ~handler. If f v raises an exception e, handler e is executed, then e is reraised.

Sourcetype 'a return = 'a Exn.Stdlib.return = {
  1. return : 'jump. 'a -> 'jump;
}
Sourceval with_return : ('a return -> 'a) -> 'a
Sourcemodule Temporal = Temporal
Sourcemodule Year = Temporal.Year
Sourcemodule Date = Temporal.Date
Sourcemodule Time = Temporal.Time
Sourcemodule Datetime = Temporal.Datetime
Sourcemodule IntRange = IntRange
Sourcemodule List : sig ... end
include module type of struct include Xlist.Stdlib end
Sourceval (--) : int -> int -> int list

same as from_to. [f--t = [f..t]]

Sourceval (+::=) : 'a list ref -> 'a -> unit

Same as accum

Sourcemodule Array : sig ... end
Sourcemodule Format : sig ... end
Sourcemodule Hashtbl : sig ... end
Sourcemodule String : sig ... end
include module type of struct include Xstring.Stdlib end
Sourceval chop_eols : string -> string
Sourcemodule Bytes : sig ... end
Sourcemodule Lazy : sig ... end
Sourcemodule Filename : sig ... end
include module type of struct include Xfilename.Stdlib end
Sourceval (^/) : string -> string -> string

Filename concatenation. If the second argument is absolute, the first is ignored and the second is just returened.

"hello" ^/ "world" = "hello/world" "hello" ^/ "/world" = "/world"

Sourcemodule Filepath = Filepath
Sourcemodule Unix : sig ... end
include module type of struct include Xunix.Stdlib end
Sourceval timed_message : string -> ('a -> 'b) -> 'a -> 'b

timed_message mes f returns a function as same as f but with printing computation times to stderr.

Sourcemodule Printf : sig ... end
Sourcemodule Sys : sig ... end
Sourcemodule Set = Xset
Sourcemodule StringSet : sig ... end
Sourcemodule IntSet : sig ... end
Sourcemodule Int64 : sig ... end
Sourcemodule Printexc : sig ... end
Sourcemodule Obj : sig ... end
Sourcemodule URL = URL
Sourcemodule Gc : sig ... end
Sourcemodule UniqueID = UniqueID
Sourcemodule Once = Once
Sourcemodule Shell = Shell
Sourcemodule Lexing : sig ... end
Sourcemodule Command = Command