In a dynamic language like Python you can selectively import different modules depending on configuration. We could achieve something a little like that by importing both modules but choosing which symbols to use at runtime with indirect calls. Consider.
func makeTree(xs : List('x)) -> Tree('x) {
var T
if length(xs) < 100 {
T = import BTree
} else {
T = import RBTree
}
var $tree = T.new()
for (x : xs) {
T.insert(x, $tree)
}
return $tree
}
This example assumes some other syntaxes we don't have yet, and the return value isn't well typed. It's more like pseudo code.
At runtime T doesn't actually point to the module, instead T.new and T.insert point to the only two symbols required and the calls are indirect. They may be tupled but to tuple or not-tuple is an optimisation. Both modules need to be present during compilation this is not the same thing as dynamic linking.
In a dynamic language like Python you can selectively import different modules depending on configuration. We could achieve something a little like that by importing both modules but choosing which symbols to use at runtime with indirect calls. Consider.
This example assumes some other syntaxes we don't have yet, and the return value isn't well typed. It's more like pseudo code.
At runtime
Tdoesn't actually point to the module, insteadT.newandT.insertpoint to the only two symbols required and the calls are indirect. They may be tupled but to tuple or not-tuple is an optimisation. Both modules need to be present during compilation this is not the same thing as dynamic linking.