Memoizing effectful calls #
memoize compute stores the first result of each call in an association list. The underlying
computation may be probabilistic or interact with other stateful services. A cache hit does not
repeat its effects. The representation is an ordinary list, so later computational realizations
can charge for lookup and storage without changing the client program.
Main definitions #
Cslib.memoize: cache one effectful computation per key in a list.
Main results #
Cslib.memoize_repeat: repeated queries share their answer and perform the effect once.Cslib.memoize_map: injective key representations and mapped values preserve execution.
References #
Adapted from Foundations/Control/Monad/Memoize.lean on the cslib crypto branch at
5ff69ca93402e7c947208dc56396d6d86203ccd8.
Two immediate calls at the same key return the same value and perform the effect once.
Injectively re-encode cache keys and map stored values. If the samplers commute with the value map, memoization preserves the complete result and re-encoded cache, including duplicates.
Interpreting the effects commutes with memoization, including its final list cache.