array-memoize-0.6.0: Memoization combinators using arrays for finite sub-domains of functions
Safe HaskellSafe-Inferred
LanguageHaskell98

Data.Function.ArrayMemoize

Synopsis

Documentation

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

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 -> b Source #

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 -> b Source #

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 -> b Source #

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 b Source #

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 -> b Source #

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 -> b Source #

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 -> b Source #

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 -> b Source #

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 -> b Source #

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 -> b Source #

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

class ArrayMemoizable a where Source #

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 #

Instances

Instances details
ArrayMemoizable Integer Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Methods

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

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

ArrayMemoizable Bool Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Methods

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

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

ArrayMemoizable Char Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Methods

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

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

ArrayMemoizable Double Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Methods

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

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

ArrayMemoizable Float Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Methods

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

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

ArrayMemoizable Int Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Methods

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

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

class IArray UArray a => UArrayMemoizable a where Source #

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 a Source #

Instances

Instances details
UArrayMemoizable Char Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Methods

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

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

readUArray :: Ix i => IOUArray i Char -> i -> IO Char Source #

UArrayMemoizable Double Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Methods

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

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

readUArray :: Ix i => IOUArray i Double -> i -> IO Double Source #

UArrayMemoizable Float Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Methods

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

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

readUArray :: Ix i => IOUArray i Float -> i -> IO Float Source #

UArrayMemoizable Int Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Methods

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

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

readUArray :: Ix i => IOUArray i Int -> i -> IO Int Source #

class (Ix (Discrete t), Enum (Discrete t)) => Discretize t where Source #

Discretization of float/double values and tuples

Associated Types

type Discrete t Source #

Methods

discretize :: t -> t -> Discrete t Source #

continuize :: t -> Discrete t -> t Source #

Instances

Instances details
Discretize Double Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Associated Types

type Discrete Double 
Instance details

Defined in Data.Function.ArrayMemoize

Discretize Float Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Associated Types

type Discrete Float 
Instance details

Defined in Data.Function.ArrayMemoize

(Discretize a, Discretize b) => Discretize (a, b) Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Associated Types

type Discrete (a, b) 
Instance details

Defined in Data.Function.ArrayMemoize

type Discrete (a, b) = (Discrete a, Discrete b)

Methods

discretize :: (a, b) -> (a, b) -> Discrete (a, b) Source #

continuize :: (a, b) -> Discrete (a, b) -> (a, b) Source #

(Discretize a, Discretize b, Discretize c) => Discretize (a, b, c) Source # 
Instance details

Defined in Data.Function.ArrayMemoize

Associated Types

type Discrete (a, b, c) 
Instance details

Defined in Data.Function.ArrayMemoize

type Discrete (a, b, c) = (Discrete a, Discrete b, Discrete c)

Methods

discretize :: (a, b, c) -> (a, b, c) -> Discrete (a, b, c) Source #

continuize :: (a, b, c) -> Discrete (a, b, c) -> (a, b, c) Source #

discrete :: Discretize a => (a -> b) -> a -> Discrete a -> b Source #

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

Orphan instances

(Enum a, Enum b) => Enum (a, b) Source # 
Instance details

Methods

succ :: (a, b) -> (a, b) #

pred :: (a, b) -> (a, b) #

toEnum :: Int -> (a, b) #

fromEnum :: (a, b) -> Int #

enumFrom :: (a, b) -> [(a, b)] #

enumFromThen :: (a, b) -> (a, b) -> [(a, b)] #

enumFromTo :: (a, b) -> (a, b) -> [(a, b)] #

enumFromThenTo :: (a, b) -> (a, b) -> (a, b) -> [(a, b)] #

(Num a, Num b) => Num (a, b) Source # 
Instance details

Methods

(+) :: (a, b) -> (a, b) -> (a, b) #

(-) :: (a, b) -> (a, b) -> (a, b) #

(*) :: (a, b) -> (a, b) -> (a, b) #

negate :: (a, b) -> (a, b) #

abs :: (a, b) -> (a, b) #

signum :: (a, b) -> (a, b) #

fromInteger :: Integer -> (a, b) #

(Enum a, Enum b, Enum c) => Enum (a, b, c) Source # 
Instance details

Methods

succ :: (a, b, c) -> (a, b, c) #

pred :: (a, b, c) -> (a, b, c) #

toEnum :: Int -> (a, b, c) #

fromEnum :: (a, b, c) -> Int #

enumFrom :: (a, b, c) -> [(a, b, c)] #

enumFromThen :: (a, b, c) -> (a, b, c) -> [(a, b, c)] #

enumFromTo :: (a, b, c) -> (a, b, c) -> [(a, b, c)] #

enumFromThenTo :: (a, b, c) -> (a, b, c) -> (a, b, c) -> [(a, b, c)] #

(Num a, Num b, Num c) => Num (a, b, c) Source # 
Instance details

Methods

(+) :: (a, b, c) -> (a, b, c) -> (a, b, c) #

(-) :: (a, b, c) -> (a, b, c) -> (a, b, c) #

(*) :: (a, b, c) -> (a, b, c) -> (a, b, c) #

negate :: (a, b, c) -> (a, b, c) #

abs :: (a, b, c) -> (a, b, c) #

signum :: (a, b, c) -> (a, b, c) #

fromInteger :: Integer -> (a, b, c) #