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:
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.
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: