Memoization.jl
Memoization.jl copied to clipboard
make it easier to use statically typed containers
As it is now the cache generated by @memoize
will always by of type Any => Any
which can be sub-optimal. If argument and return types of the memoized function are known (and known to not change) it would be nice if the user could provide a fully typed container type for the cache.
However, since @memoize
internally keeps function arguments in a tuple of two tuples (one for positional and one for named arguments), key types are a bit inconvenient. A function with a single Int
argument for example produces Tuple{Tuple{Int64}, Tuple{}}
as a key type for the internal cache.
If there is no simple way to sanitize the key type it would be useful to at least have a function that maps argument types of a function to the key type used by the macro, so that this for example would work:
@memoize Dict{memo_key_type(Int, Float64), String} function my_fun(x, y)
"bla"
end