1(* 2 * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 *) 6 7signature OPTION_EXTRAS = 8sig 9 (* 10 `get_or_else f opt` unwraps `opt` if it is `SOME x`. Otherwise, 11 it uses `f` to construct a value. 12 13 This is useful when `f` has side effects, such as throwing an 14 exception or printing a warning. 15 *) 16 val get_or_else: (unit -> 'a) -> 'a option -> 'a 17end 18 19structure OptionExtras: OPTION_EXTRAS = 20struct 21 22fun get_or_else _ (SOME x) = x 23 | get_or_else f NONE = f () 24 25end