Module rmemo

memoization server.

Copyright © 2015, Tuncer Ayaz

Behaviours: gen_server.

Authors: Tuncer Ayaz.

Description

memoization server

Data Types

error()

error() = {error, reason()}

fun_args()

fun_args() = list()

fun_name()

fun_name() = atom()

reason()

reason() = term()

start_link_res()

start_link_res() = start_res()

start_res()

start_res() = {ok, pid()} | ignore | error()

Function Index

call/2 Call function and memoize result.
call/3 Call function and memoize result.
start/0 Start the server.
start_link/0 Start the server.
stop/0 Stop the server.

Function Details

call/2

call(F::function(), A::fun_args()) -> term()

Call function and memoize result

Instead of

Res = Fun(A1, A2, [List1])

you call

Res = memo:call(Fun, [A1, A2, [List1]])

or instead of

Res = mod:expensive_function(A1, A2, [List1])

you call

Res = memo:call(fun mod:expensive_function/3, [A1, A2, [List1]])

and any subsequent call will fetch the cached result and avoid the computation.

This is of course only useful for expensive computations that are known to produce the same result given same arguments. It's worth mentioning that your call should be side-effect free, as naturally those won't be replayed.

call/3

call(M::module(), F::fun_name(), A::fun_args()) -> term()

Call function and memoize result

Instead of

Res = mod:expensive_function(A1, A2, [List1])

you call

Res = memo:call(mod, expensive_function, [A1, A2, [List1]])

and any subsequent call will fetch the cached result and avoid the computation.

This is of course only useful for expensive computations that are known to produce the same result given same arguments. It's worth mentioning that your call should be side-effect free, as naturally those won't be replayed.%%

start/0

start() -> start_res()

Start the server

start_link/0

start_link() -> start_link_res()

Start the server

stop/0

stop() -> any()

Stop the server


Generated by EDoc