[Grace-core] inconsistent defaults with modules

Kim Bruce KIM at CS.POMONA.EDU
Fri May 30 00:12:08 PDT 2014


Our story for modules has always been that they are modeled as objects.  That is, when the user imports a library module,
   import "myLib" as ml
the code in a library module is implicitly wrapped in an object expression that is now made available via a definition which associates the identifier ml with the object.

However, access to the features of an imported module like ml is inconsistent with access to features of regularly defined objects.  

Normally, the default access for methods and type definitions is public, while default access for instance variables and definitions is confidential.  Of course, each may be overridden as desired.

However, the default for modules is that everything is public, and in fact attempts to annotate definitions and variable declarations to be confidential are accepted by the compiler, but ignored.  I.e., they are always visible to importing modules no matter what annotation is attached.  Interestingly, annotating a method to be confidential is effective.  It makes it invisible in the importing module.

While it would be a bit of a pain to annotate definitions (and variables if needed) to be public, I believe this is much more consistent with the rest of the language design.  

I've always been puzzled why the compiler does not implicitly wrap the code in a module/program as an object and treat it like all the other objects in the program.  A relatively easy fix may be to fix the compiler to do this, treating an imported module exactly like the other objects.  Is there a resin this should not be done?

Kim


More information about the Grace-core mailing list