logo       

Re: The public interface of a program unit in Scala: msg#00455

lang.scala

Subject: Re: The public interface of a program unit in Scala



On 1/28/07, Vijay Saraswat <vijay@xxxxxxxxxxxx> wrote:
(In the spirit of designing a language for readability vs writability.)

For the purposes of this note, let us use the term "public interface of
a program unit" to mean the information about the program unit that is
relevant to its use. (Here I mean "interface" in the colloquial sense, I
will use the phrase JavaInterface to refer to Java's intefaces.)

...

Has someone worked out the corresponding answer for Scala?

Not that I know of. I think this would make very interesting research, though!

In particular, what do I need to keep in my head about implicits
(impllicit parameters, implicit defs) and traits, case classes and
pattern-matching?

Implicits are hairy, but can probably be left out of most of the discussion.
Traits are interesting, as you have noted. Case classes and pattern matching
don't add anything new, IMO.

e.g. it seems the public interface needs to include the inheritance
graph G of a trait (and the types of the members of the classes/traits
in that graph), because each use of a trait requires the construction of
a class linearization (Sec 5.1.2), and this depends on G.


That's correct. However,  I believe that you need not care about the inheritance graph of
T in the following two situations:

 - If T is a class (because then inheritance graph of T will be in its entirety the prefix of every subclass/subtrait linearization. That is, subclasses or subtraits need not care about the order of classes in this linearization, it's sufficient to know what the set of base classes is.

 - If T is an interface (i.e. T has not state or methods, and the same is the case for
   T's parents). In that case, the linearization of T is uninteresting because it implements
   no behavior.

So those Scala classes that are expressible in Java have the same public interface as in Java. Note that this is not trivially true. Since Scala has more ways to form classes and other program contexts, it would be conceivable that even a Java-like class or interface needs a richer public interface. However, I believe that this is not the case.

Cheers

 -- Martin


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise