Module type Fix.MEMOIZER
val visibly_memoize : (key -> 'a) -> (key -> 'a) * 'a t
val fix : (key -> 'a) fix
A recursive memoization combinator.
exception
Cycle of key list * key
defensive_fix
works likefix
, except it additionally detects circular dependencies, which can arise if the second-order function supplied by the user does not follow a well-founded recursion pattern. When the user invokesf x
, wheref
is the function returned bydefensive_fix
, if a cyclic dependency is detected, thenCycle (zs, z)
is raised, where the listzs
begins withz
and continues with a series of intermediate keys, leading back toz
. Note that undetected divergence remains possible; this corresponds to an infinite dependency chain, without a cycle.