[Types-sig] Static typing: Towards closure?

Martijn Faassen faassen@vet.uu.nl
Thu, 20 Jan 2000 23:49:12 +0100


David Ascher wrote:
> Martijn Faassen:
> 
> > Interfaces can be implied:
> >
> > class Foo implements Alpha:
> [...]
> > class Bar implements Alpha:
> [..]
> > Alpha is now deduced to be the following interface:
> 
> This is very odd, IMO.  I'd expect Python not to *deduce* the interface but
> to *check* that the interface is indeed being followed.

Yes, check when the interface is *used*:

def myfunc(a: Alpha):
    ...

If a isn't of class Foo or Bar in this case, there'd be a compile-time error.
If you used anything on a that is not part of the intersection of the
interfaces of class Foo and Bar, you'd also get a compile-time error.

> > These consequences may be advantages during development;
> > interfaces (or types) can be quickly and conveniently created and used,
> > and they are always _right_; we're not bothered by interface compliance
> > errors as the interfaces are implied.
> 
> How does the deduced interface get communicated to the programmer, and/or
> used?
> 
> class MyFileObject implements Stream:
>   def read_bytes(numBytes : integer) -> string
> 
> class MyOtherFileObject implements Stream:
>   def readBytes(numBytes : integer) -> string
> 
> leads to an empty interface Stream, due to a typo.

Empty interfaces should of course be detected by the compiler and complained
about. Though you may be right in that a typo could screw up things --
if the intersection of MyFileObject and MyOtherFileObject is not empty
but misses a crucial method due to a typo, the compiler will complain when
an attempt is made to use either of the methods involved. You'd have to
go through all classes implementing the interface in order to fix the
problem. That's Not Nice and probably destroys my idea, unless I can
figure out how to neutralize this problem. Explicit interfaces don't
have this problem.

> What are the semantic consequences of the implements statement?

If the interface (Stream) is not explicitly defined somewhere, it'll be
the intersection of the interfaces of the classes MyFileObject and 
MyOtherFileObject.

> I'm missing the point, I fear.
[snip]

The point is the intersection concept. Does my previous post make more
sense with this new information? 

Regards,

Martijn