Combinators
val const : 'a -> _ -> 'aconst cis a function that always returns the valuec. For any argumentx,(const c) xisc.
val flip : ('a -> 'b -> 'c) -> 'b -> 'a -> 'cflip freverses the argument order of the binary functionf. For any argumentsxandy,(flip f) x yisf y x.
val negate : ('a -> bool) -> 'a -> boolnegate pis the negation of the predicate functionp. For any argumentx,(negate p) xisnot (p x).
Exception handling
val protect : finally:(unit -> unit) -> (unit -> 'a) -> 'aprotect ~finally workinvokeswork ()and thenfinally ()beforework ()returns with its value or an exception. In the latter case the exception is re-raised afterfinally (). Iffinally ()raises an exception, then the exceptionFinally_raisedis raised instead.protectcan be used to enforce local invariants whetherwork ()returns normally or raises an exception. However, it does not protect against unexpected exceptions raised insidefinally ()such asStdlib.Out_of_memory,Stdlib.Stack_overflow, or asynchronous exceptions raised by signal handlers (e.g.Sys.Break).Note: It is a programming error if other kinds of exceptions are raised by
finally, as any exception raised inwork ()will be lost in the event of aFinally_raisedexception. Therefore, one should make sure to handle those inside the finally.
exception Finally_raised of exnFinally_raised exnis raised byprotect ~finally workwhenfinallyraises an exceptionexn. This exception denotes either an unexpected exception or a programming error. As a general rule, one should not catch aFinally_raisedexception except as part of a catch-all handler.