Memoize IO actions,
performing them at most once,
but recalling their result for subsequent invocations.
This library provides three sequencing strategies:
ioMemo), eager (
ioMemo'), and concurrent (
The lazy and eager approaches give stronger sequencing guarantees.
The following property holds:
join . ioMemo === id.
The same is true for
Also, for the three memoizers in this library, the memory allocated for the result will not be available for garbage collection until the corresponding memoized action is also available for garbage collection, unless your compiler performs deep magicks.
Memoize an IO action. The action will be performed the first time that it its value is demanded; all subsequent invocations will simply recall the value acquired from the first call. If the value is never demanded, then the action will never be performed.
This is basically a safe version of
This function is also thread-safe:
it is guaranteed that the action passed in
will be performed exactly 0 or 1 times
by this code. Exceptions will be propagated
to the caller.
getLine' <- ioMemo getLine
replicateM 3 getLine'Hello ["Hello", "Hello", "Hello"]
Memoize an IO action. The action will be performed immediately; all subsequent invocations will recall the value acquired.