Skip to content

Module expressions #464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
PaulBone opened this issue Apr 4, 2025 · 0 comments
Open

Module expressions #464

PaulBone opened this issue Apr 4, 2025 · 0 comments
Labels
component: compiler Concerning the compiler component: language The Definition of the Plasma Language meta: triaged Has the issue been triaged yet? skill: mercury status: new A new bug, we may or may not fix it. type: enhancement
Milestone

Comments

@PaulBone
Copy link
Member

PaulBone commented Apr 4, 2025

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.

@PaulBone PaulBone added component: compiler Concerning the compiler component: language The Definition of the Plasma Language meta: triaged Has the issue been triaged yet? skill: mercury status: new A new bug, we may or may not fix it. type: enhancement labels Apr 4, 2025
@PaulBone PaulBone added this to the Modules Extra milestone Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: compiler Concerning the compiler component: language The Definition of the Plasma Language meta: triaged Has the issue been triaged yet? skill: mercury status: new A new bug, we may or may not fix it. type: enhancement
Projects
None yet
Development

No branches or pull requests

1 participant