-
Notifications
You must be signed in to change notification settings - Fork 14
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
Implement namespaces #388
Implement namespaces #388
Conversation
The current state of the implementation already allows parsing def main() = {
def foo() = effekt::println("foo")
main::foo();
// explicit
val l2: List[effekt::Int] = effekt::list::Cons(1, effekt::list::Cons(2, effekt::list::Nil()))
effekt::list::map(l2) { x => effekt::infixAdd(x, 1) }
} but namer simply ignores the qualifiers. This way all existing programs are (still) fully backwards compatible. |
The following example now works: namespace internals {
def add(n: Int, m: Int) = nested::helper(n, m)
namespace nested {
def before() = nested::increment(1)
def increment(n: Int): Int = internals::add(n, 1)
def incrementAlternative(n: Int) = internals::nested::increment(n)
def helper(n: Int, m: Int): Int = n + m
}
}
def main() = {
println(internals::nested::increment(7))
println(internals::nested::incrementAlternative(8))
} |
Basic namespacing now already works. What could be done in the future is:
|
Turns out that allowing Also, namespaces are only allowed to contain definitions (that is no statements). |
I am sufficiently happy with the implementation now and would be willing to merge (we can always still bike-shed) syntax, later (this is trivial to change). Maybe you can take a look at it once more (especially the tests to get an impression of what is supposed to be working)? |
Just to clarify, what introduces a new namespace implicitly? According to the above, it seems like a new function definition does ( |
Edit: I now recognize that the example is my example for above... that was only the parser! This is not how namespaces are implemented. A function introduces a new (anonymous) namespace-root. That is def somefunction() = {
namespace nested {
def go() = println("hello")
}
nested::go()
} is valid. But all namespaces in the function will be flattened out and definitions become function-local definitions. To be more precise, if we use We could explicitly distinguish between these roots (ie., |
I am merging this for now since I want to merge the implementation anyways, modulo bugs and future changes of the design (which should be based on top of this). Let's revisit it in the next Effekt group meeting and potentially bike-shed / and redesign things more. |
The purpose of this PR is to experiment with an implementation of namespaces.
The design is supposed to be fully backwards compatible (for now) while preparing for additional future extensions such as those listed in #389
For a discussion on the design also see: https://gist.github.com/jiribenes/8195243f56a454d3465b06f02e8bb5a2?permalink_comment_id=4872857#gistcomment-4872857