Basic types and definitions required throughout the system.
Raised when finalization after an exception failed, too. The first exception argument is the one raised by the initial function, the second exception the one raised by the finalizer.
Types for use as markers in phantom types. One should not expose functions for converting between read_only/immutable/read_write because the private types expose the subtyping. Users would say "(db :> read_only Db.t)" to cast. The difference between read-only and immutable is that someone else can change a read-only object, while immutable never changes.
These types are deprecated in favor of the types included from Perms.Export
module
below.
never_returns
should be used as the return type of functions that don't return and
might block forever, rather than 'a
or _
. This forces callers of such functions
to have a call to never_returns
at the call site, which makes it clear to readers
what's going on. We do not intend to use this type for functions such as failwithf
that always raise an exception.
See exn.mli
#
return
| : 'b . 'a -> 'b | ; |
with_return f
allows for something like the return statement in C within f
. There
are three ways f
can terminate:
1. If f
calls r.return x
, then x
is returned by with_return
.
2. If f
evaluates to a value x
, then x
is returned by with_return
.
3. If f
raises an exception, it escapes with_return
.
Here is a typical example:
let find l ~f =
with_return (fun r ->
List.iter l ~f:(fun x -> if f x then r.return (Some x));
None
)
It is only because of a deficiency of ML types that with_return
doesn't have type:
val with_return : 'a. (('a -> ('b. 'b)) -> 'a) -> 'a
but we can slightly increase the scope of 'b, without changing the meaning of the type and then we get
type 'a return = { return : 'b . 'a -> 'b }
val with_return : ('a return -> 'a) -> 'a
But the actual reason we chose to use a record type with polymorphic field is that
otherwise we would have to clobber the namespace of functions with return
and that is
undesirable because return
would get hidden as soon as we open any monad. We
considered names different than return
but everything seemed worse than just having
return
as a record field. We are clobbering the namespace of record fields but that
is much more acceptable.
We disable ==
and !=
and replace them with the longer and more mnemonic
phys_equal
because they too easily lead to mistakes (for example they don't even
work right on Int64 or Float). One can usually use the equal
function for a
specific type, or use (=) or (<>) for built in types like char, int, float.
Note that 4.02 increased cases where objects are physically equal.
phys_same
is like phys_equal
, but with a more general type. phys_same
is useful
when dealing with existential types, when one has a packed value and an unpacked value
that one wants to check are physically equal. One can't use phys_equal
in such a
situation because the types are different.
Raised if malloc in C bindings fail (errno * size).
The following section contains definitions that hide operations from the standard library that are considered problematic or confusing, or simply redundant.
we have our own version of these two, the INRIA version doesn't release the runtime lock.