microsoft/BosqueLanguage

Memoize (and singleton) pragmas

mrkmarron opened this issue · 0 comments

Memoization and/or singletons with lazy initializtion are very useful patterns and important performance optimizations. In Bosque they are also semantics preserving since there is no reference identity. However, implementing them in a functaional language can be hard.

So, we want to implement "optmization pragmas" for functions/methods for singleton and memoize optmizations.

#pragma memoize(cache=256, replace="LRU")
function square(x: Int): Int {
...
}

As shown in the example we want to allow control over the size and replacement policies. We can also check that the arguments are valid for comparison at compile time.