sequence xs computes a sequence of computations
xs in the left to right order.
module Fn : sig ... end
Various function combinators lifted into the Kleisli category.
module Pair : sig ... end
The pair interface lifted into the monad.
module Triple : sig ... end
The triple interface lifted into a monad.
module Lift : sig ... end
Lifts functions into the monad.
module Exn : sig ... end
Interacting between monads and language exceptions
module Collection : sig ... end
Lifts collection interface into the monad.
The Monad.Collection.S interface for sequences
include Monads.Std.Monad.Syntax.S with type 'a t := 'a t
val (!!) : 'a -> 'a t
include Monads.Std.Monad.Syntax.Let.S with type 'a t := 'a t
include Core_kernel.Monad.S with type 'a t := 'a t
t >>= f returns a computation that sequences the computations represented by two monad elements. The resulting computation first does
t to yield a value
v, and then runs the computation returned by
module Monad_infix : sig ... end
val return : 'a -> 'a t
return v returns the (trivial) computation that returns v.
ignore_m t is
map t ~f:(fun _ -> ()).
ignore_m used to be called
ignore, but we decided that was a bad name, because it shadowed the widely used
Caml.ignore. Some monads still do
let ignore = ignore_m for historical reasons.
module Let_syntax : sig ... end
These are convenient to have in scope when programming with a monad:
Monadic operators, see Monad.Syntax.S for more.
require a ~that:p requires that an attribute
a has one and only one value that satisfies a predicate
p. It is an error, if there are no such values, or if there are more than one value.
request a ~that:p request no more than one value of an attribute
a, that satisfies a predicate
p. The returned value is wrapped in an option. If there are more than one satisfying value, then it is an error.
foreach query ~f:action applies an
action for each value of an attributes specified in the query. The
query value is built using a domain specific language embedded into OCaml. This language is very similar to SQL, and has join and where clauses, e.g.,
let better_than_average_students = foreach Query.(begin select ~where:(students.(gpa) > float 3.5) ~join:[ [field classid]; [ field teacher ~from:students; field id ~from:teachers ]] (from students $ teachers) end) ~f:(fun s t -> return (s,t))
The type of the
query value encodes the type of the function
f. A well formed query has a type of form
(t1 -> t2 -> .. -> tm -> 'a t) -> 'a t, where
tm are types of attributes enumerated in the
from clause (in that particular order).
Query module documentation for more information about the query EDSL.
collect query is the same as
foreach query ~f:ident
provide attr v1 v2 ... vm stores the constituents of an attribute value in the document. An attribute type encodes not only the type of an attribute value, but also a type and the order of the fields. Thus, the
attribute itself captures a format of the attribute representation, the same as
format is used in printf-like functions. In that sense, the
provide function is variadic, where the first argument (the attribute) defines the type and the arity of the function.
fail error aborts an inference process with the specified
failf fmt args... () constructs an error based on the specified format
fmt and arguments, terminated by the unit value
failf "the file type %s is unsupported" name ()
Note: don't forget to terminate a sequence of arguments with an extra unit value. See the corresponding
failwithf function for the reason, why this extra argument is needed.
eval property document makes an inference of a
property based on facts stored in a
document. If all requirements are satisfied and no errors occurred the inferred result.
For example, given the property
names_of_best_students, defined as,
let names_of_best_students = foreach Query.(select (from students) ~where:(students.(gpa) > float 3.8)) ~f:(fun s -> return (Student.name s))
we can evaluate this property, with
to get a sequence (possibly empty) of all students that have the GPA score greater than 3.8.
exec op doc executes an operation
op that, presumably, updates the document
doc, returns an updated version.
run op doc runs an operation
op that does some inference as well as may update the document. This function is a usual part of a generic state monad interface, and is provided for the consistency. Usually, it is a bad idea, or a notion of a bad style to use this function.