Function adapton::engine::thunk
[−]
[src]
pub fn thunk<Arg: Hash + Eq + Debug + Clone + 'static, Spurious: Clone + 'static, Res: Hash + Eq + Debug + Clone + 'static>(
id: ArtIdChoice,
prog_pt: ProgPt,
fn_box: Rc<Box<Fn(Arg, Spurious) -> Res>>,
arg: Arg,
spurious: Spurious
) -> Art<Res>
Allocates a thunk, an Art<T>
that consists of a suspended
computation that produces a value of type T
.
Use the macros thunk!
, memo!
and eager!
to create and force
thunks with less typing.
A full invocation of thunk
consists of the following:
It has an
id
of typeArtIdChoice
, either giving aName
, 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 >>
. TheRc<_>
is required for cloning this function, which we generally want to do. We divide the arguments into the ordinary arguments of typeArg
, and additional "spurious" arguments. When we judge whether a thunk's closing environment is equal to another, we use the typeArg
. When we judge whether the result of a thunk has changed or not, we use the typeRes
.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 (
ProgPt
,ArtIdChoice
,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.