One of the benefits of pure FP is the ability to cache, but I can't seem to find anything in the documentation about it. Is there a way to explicitly tell Roc to cache one of or all functions in an app?
I tried implementing caching with a Cache value cache
monad, but (with the problem I was solving, at least- aoc day12) it crashed with a stack overflow.
Roc does not have this currently
Would need to be done manually with a dictionary
Recently we realized that we have a bug in code generation related to the stack that makes stack overflows more common. So you may have it that even if your function was tail recursive
Oh okay, a compiler bug makes more sense. Thanks for the reply!
I'd like to make an interface like so
interface Cache
exposes []
imports []
Cache a cache := (cache -> (a, cache))
map : Cache a cache, (a -> b) -> Cache b cache
updateCache : Cache r cache, (cache -> cache) -> Cache r cache
andThen : Cache a cache, (a -> Cache b cache) -> Cache b cache
sequence : List ({} -> Cache a cache) -> Cache (List a) cache
store : cache -> Cache {} cache
ignore : a -> Cache a cache
get : Cache cache cache
run : Cache r cache, cache -> r
Where the elements of sequence are thunked to optimize recursive functions, though I suppose that won't be necessary when function caching is implemented.
I'll mark this thread as solved.
Fletch Canny has marked this topic as resolved.
Last updated: Jul 06 2025 at 12:14 UTC