array-memoize-0.6.0: Memoization combinators using arrays for finite sub-domains of functions

Data.Function.ArrayMemoize

Synopsis

# Documentation

arrayMemo :: (Ix a, ArrayMemoizable b) => (a, a) -> (a -> b) -> a -> bSource

Memoize a function over a finite (sub)domain, using an array (boxed), e.g., ``` arrayMemo (0, 20) f ``` memoizes f between from 0 to 20.

arrayMemoFix :: (Ix a, ArrayMemoizable b) => (a, a) -> ((a -> b) -> a -> b) -> a -> bSource

Memoize a fixed point of a function over a sub domain. Similar to `fix`, but over `arrayMemo`, passing a function a memoized version of itself.

arrayMemoFixMutual :: (ArrayMemoizable b, ArrayMemoizable d, Ix a, Ix c) => (a, a) -> (c, c) -> ((a -> b) -> (c -> d) -> a -> b) -> ((a -> b) -> (c -> d) -> c -> d) -> a -> bSource

Memoize a mutual fixed point for two functions (over sub domains of these functions).

arrayMemoFixMutual3 :: (ArrayMemoizable b, ArrayMemoizable d, ArrayMemoizable f, Ix a, Ix c, Ix e) => (a, a) -> (c, c) -> (e, e) -> ((a -> b) -> (c -> d) -> (e -> f) -> a -> b) -> ((a -> b) -> (c -> d) -> (e -> f) -> c -> d) -> ((a -> b) -> (c -> d) -> (e -> f) -> e -> f) -> a -> bSource

Memoize a mutual fixed point for three functions (over sub domains of these functions).

uarrayMemoFixIO :: (Ix a, UArrayMemoizable b) => (a, a) -> ((a -> IO b) -> a -> IO b) -> a -> IO bSource

Memoize a function over a finite (sub)domain, using an unboxed `IO` array. This requires the incoming function to return results in the `IO` monad, but should preferable be pure.

discreteMemo :: (ArrayMemoizable b, Discretize a) => (a, a) -> a -> (a -> b) -> Discrete a -> bSource

Memoize and discretize a function over a finite (sub)domain, using an array. e.g. ``` discretemMemo (0.0, 10.0) 2.0 f ``` returns a discretized version of f (with the discrete type defined by `Discrete`) in the range 0.0 to 10.0 with step size 2.0 (i.e., the resulting discrete domain is of size 5).

discreteMemoFix :: (ArrayMemoizable b, Discretize a) => (a, a) -> a -> ((a -> b) -> a -> b) -> Discrete a -> bSource

Memoize and discretize a fixed point of a function over a subdomain with discretization step

quantizedMemo :: (ArrayMemoizable b, Discretize a) => (a, a) -> a -> (a -> b) -> a -> bSource

Memoize and quantize a function over a finite (sub)domain, using a boxed array, e.g, ``` quantizedMemo (0.0, 10.0) 2.0 f ``` memoizes f between 0.0 and 10.0 with step size 2.0 (i.e. the function is quantized into 5 parts, memoized into an array of size 5).

quantizedMemoFix :: (ArrayMemoizable b, Discretize a) => (a, a) -> a -> ((a -> b) -> a -> b) -> a -> bSource

Memoize and quantize a fixed point of a function. Similar to `fix`, but using `quantizedMemo` to pass the fixed function a quantized memoized version of itself, therefore memoizing any recursive calls.

quantizedMemoFixMutual :: (ArrayMemoizable b, ArrayMemoizable d, Discretize a, Discretize c) => (a, a) -> a -> (c, c) -> c -> ((a -> b) -> (c -> d) -> a -> b) -> ((a -> b) -> (c -> d) -> c -> d) -> a -> bSource

Memoize and quantize a mutually recursive fixed point of two functions.

quantizedMemoFixMutual3 :: (ArrayMemoizable b, ArrayMemoizable d, ArrayMemoizable f, Discretize a, Discretize c, Discretize e) => (a, a) -> a -> (c, c) -> c -> (e, e) -> e -> ((a -> b) -> (c -> d) -> (e -> f) -> a -> b) -> ((a -> b) -> (c -> d) -> (e -> f) -> c -> d) -> ((a -> b) -> (c -> d) -> (e -> f) -> e -> f) -> a -> bSource

Memoize and quantize a mutually recursive fixed point of three functions.

class ArrayMemoizable a whereSource

`ArrayMemoizable` defines the subset of types for which we can do array memoization

Methods

newArray_ :: Ix i => (i, i) -> ST s (STArray s i a)Source

writeArray :: Ix i => STArray s i a -> i -> a -> ST s ()Source

class IArray UArray a => UArrayMemoizable a whereSource

`UArrayMemoizable` defines the subset of types for which we can do unboxed IOUArray memoization

Methods

newUArray_ :: Ix i => (i, i) -> IO (IOUArray i a)Source

writeUArray :: Ix i => IOUArray i a -> i -> a -> IO ()Source

readUArray :: Ix i => IOUArray i a -> i -> IO aSource

class (Ix (Discrete t), Enum (Discrete t)) => Discretize t whereSource

Discretization of float/double values and tuples

Associated Types

type Discrete t Source

Methods

discretize :: t -> t -> Discrete tSource

continuize :: t -> Discrete t -> tSource

Instances

 Discretize Double Discretize Float (Discretize a, Discretize b) => Discretize (a, b) (Discretize a, Discretize b, Discretize c) => Discretize (a, b, c)

discrete :: Discretize a => (a -> b) -> a -> Discrete a -> bSource

Discretized a function function. The second parameter is the discretisation step.