Can the constrain cache be global? #46
Replies: 2 comments
-
Here is a Scala snippet that I used to check when such implicit gets initialized: import scala.collection.mutable
object HelloWorld {
def main(args: Array[String]) {
run(0, true)
run(0, true)
}
def run(arg: Int, callAgain: Boolean)(implicit cache: mutable.Set[Int] = mutable.Set.empty) {
println(cache)
cache += arg
if (callAgain) {
run(arg + 1, false)
}
}
} Result:
|
Beta Was this translation helpful? Give feedback.
-
Hi @michallepicki, cool project, thanks for sharing! The constrain method could memoize everything across top-level Another thing that could be done would be to cache things according to their generalization level. So there would be a global cache for global types (those at level 0), and one additional cache per nested level. Again, not sure it's worth the over-engineering! |
Beta Was this translation helpful? Give feedback.
-
I ported the gist of the algorithm to Erlang (my repo) and started wondering - the paper and comments in code say that the
constrain
method has a cache in order to memoize results of previous subtyping tests. I am no Scala expert but from my quick testing, theimplicit cache
gets initialized to an empty mutable set every time it's called from outside of itself.Question: Can this cache be global per typing environment? Or would that break the algorithm for some edge cases? Making this change does not seem to break any of the examples included in this repo's tests.
Beta Was this translation helpful? Give feedback.
All reactions