package batteries
A community-maintained standard library extension
Install
Dune Dependency
Authors
Maintainers
Sources
v3.7.2.tar.gz
md5=1fd7bddce07cf5d244fc9427f7b5e4d4
sha512=c0f2a0fdc8253e0ea999d8d4c58bfbf32b18d251a2e1d9656bf279de5f01a33e9aabac3af4d95f465f8b671e7711ebd37218043face233340a0c11b08fa62f78
doc/batteries.unthreaded/BatReturn/index.html
Module BatReturn
Source
Local exceptions/labels/goto/return.
This module defines a mechanism akin to SML's exception generators or to a generalization of C's return
, i.e. the ability to define local labels, which may be used for immediately terminating an expression and returning a value. By opposition to usual OCaml exceptions, this mechanism
- allows polymorphic return values
- makes accidental exception catching slightly harder (while a local exception can escape its scope, it cannot be caught again by accident from this module).
Example:
let find_in_array a e =
label (fun label ->
for i = 0 to Array.length a - 1 do
if Array.get a i = e then return label (Some i)
done;
None)
@documents Return
A label which may be used to return values of type 'a
label f
creates a new label x
and invokes f x
. If, during the execution of f
, return x v
is invoked, the execution of f x
stops immediately and label f
returns v
. Otherwise, if f x
terminates normally and returns y
, label f
returns y
.
Calling return x v
from outside scope f
is a run-time error and causes termination of the program.
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>