Skip to content

Module expressions #464

@PaulBone

Description

@PaulBone

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions