pub fn thunk<Arg: Hash + Eq + Debug + Clone + 'static, Spurious: Clone + 'static, Res: Hash + Eq + Debug + Clone + 'static>(
fn_box: Rc<Box<dyn Fn(Arg, Spurious) -> Res>>,
) -> Art<Res>
Allocates a thunk, an
Art<T> that consists of a suspended
computation that produces a value of type
Use the macros
eager! to create and force
thunks with less typing.
A full invocation of
thunk consists of the following:
It has an
NameChoice, either giving a
Name, requesting structural identity, or requesting no caching whatsoever.
Its code resides at a program point, of type
ProgPt. This uniquely identifies the static elements of the suspended computation (the code, but not the closing environment).
It has a function for this code, of type
Rc<Box<Fn(Art,Spurious) -> Res >>. The
Rc<_>is required for cloning this function, which we generally want to do. We divide the arguments into the ordinary arguments of type
Arg, and additional "spurious" arguments. When we judge whether a thunk's closing environment is equal to another, we use the type
Arg. When we judge whether the result of a thunk has changed or not, we use the type
Spurious arguments are not compared for equality, and are ignored during the memo-matching process. They are, however, saved in the thunk and supplied to the suspended computation when it runs. Typically, these arguments consist of higher-order functions that parameterize the thunk; we make them spurious because (1) we cannot, and do not wish to compare them for equality and (2) the triple of type (
Arg) should determine these spurious arguments, if any. Because some arguments have no equality relation, the presence of these arguments is sometimes a necessary hack.