package fix

  1. Overview
  2. Docs
type key = int

A type of keys.

val memoize : (key -> 'a) -> key -> 'a

A memoization combinator for this type.

type 'a t

A memoization combinator where the memoization table is exposed.

val visibly_memoize : (key -> 'a) -> (key -> 'a) * 'a t
val fix : ((key -> 'a) -> key -> 'a) -> key -> 'a

A recursive memoization combinator.

exception Cycle of key list * key

defensive_fix works like fix, 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 invokes f x, where f is the function returned by defensive_fix, if a cyclic dependency is detected, then Cycle (zs, z) is raised, where the list zs begins with z and continues with a series of intermediate keys, leading back to z. Note that undetected divergence remains possible; this corresponds to an infinite dependency chain, without a cycle.

val defensive_fix : ((key -> 'a) -> key -> 'a) -> key -> 'a
val curried : (((('a * 'b) -> 'c) -> ('a * 'b) -> 'c) -> ('a * 'b) -> 'c) -> (('a -> 'b -> 'c) -> 'a -> 'b -> 'c) -> 'a -> 'b -> 'c

This combinator can be used to obtain a curried version of fix or defensive_fix in a concrete instance where the type key is a product type.

OCaml

Innovation. Community. Security.