2.1. The open directive

It's really boring writing qualified names all the time. Felix provides the open directive to allow you to open a module so its contents can be accesses without using qualified names. Here's a simple example:
Start C++ section to tut/examples/tut205.flx[1 /1 ]
     1: include "std";
     2: module X {
     3:   proc print_endl (a:int) { print a; endl; }
     4:   fun square (a:int):int = { return a * a; }
     5: }
     6: 
     7: open X;
     8: print_endl (square 2);
     9: 
End C++ section to tut/examples/tut205.flx[1]
Note that the open directive only affects lookup of unqualified names, or the first component of a qualified name. Lookup proceeds first in the current scope, before considering opened modules; then opened modules are considered, then the parent scope, then opened modules in the parent, etc.

The name of the module to be opened is not looked up in the modules opened by open directives in the same module as itself. Open directives in containing modules are, however, examined.

The reason for this last rule is as follows: open directives, like Felix declarations, are all considered in parallel; that is, their order of writing is irrelevant; hence, open directives are considered in a context in which none of the open directives have been applied.

It is not an error to open modules containing conflicting definitions, however, it is an error to refer to a name with conflicting definitions.

Functions with the same name in opened modules are overloaded. If two functions have the same signature, a reference will lead to an ambiguity. Such an ambiguity can be resolved by hiding such definitions in opened modules by providing a definition in the module containing the open directives. Alternatively, you can use a qualified name.

Start C++ section to tut/examples/tut206.flx[1 /1 ]
     1: include "std";
     2: module X1 {
     3:   proc printme() { print "X1"; endl; }
     4: }
     5: module X2 {
     6:   proc printme() { print "X2"; endl; }
     7: }
     8: open X1;
     9: open X2;
    10: proc printme() { print "top level"; endl; }
    11: 
    12: X1::printme();
    13: X2::printme();
    14: printme();
    15: 
End C++ section to tut/examples/tut206.flx[1]
Finally note that the effect of opening a module named X which contains an entity named X is well defined: the contained X will not be seen by other open directives, whereas the module X will not be seen by any declarations and definitions in the body of the containing scope.