/* * Copyright 2024 Jonathan Lindegaard Starup * * Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE.md file. */////// Effect for signaling that an index is out of bounds.////// Useful for instances of `Index` or `IndexMut`.///effOutOfBounds {/// Stops execution with an error message.defoutOfBounds(msg: String): Void}////// Effect for signaling that an index is out of bounds, and its functions.///pubmod OutOfBounds {////// Handles the `OutOfBounds` effect of the given function `f` by converting/// out-of-bounds errors to `Result` values.////// Returns `Ok(f(x))` if the computation completes successfully./// Returns `Err(msg)` if the computation raises `outOfBounds(msg)`.///@ExperimentalpubdefhandleWithResult(f: a -> b \ ef): a -> Result[String, b] \ (ef - OutOfBounds) = x ->run Ok(f(x)) withhandlerOutOfBounds {defoutOfBounds(msg, _k) = Err(msg) }////// Runs the `OutOfBounds` effect of the given function `f`.////// Returns `Ok(f())` if the computation completes successfully./// Returns `Err(msg)` if the computation raises `outOfBounds(msg)`.///@ExperimentalpubdefrunWithResult(f: Unit -> a \ ef): Result[String, a] \ (ef - OutOfBounds) = handleWithResult(f)()}