[Types-sig] class/module interfaces (was: const)

Greg Stein gstein@lyra.org
Thu, 30 Dec 1999 10:46:03 -0800 (PST)


On Wed, 29 Dec 1999, Paul Prescod wrote:
>...
> My point was that we need to treat modules differently than classes
> because two modules cannot export the same interface whereas two classes
> can.

We should be treating them *exactly* the same. I've been saying this for a
while now :-)

A module can export the same interface as another module. Heck, it can
export the same interface as a class.

---- a.py ----
def foo(x: Int)->String:
  return "hi " + str(x)

bar = 5
--------------

import a

print a.foo(5), a.bar

class xyz:
  bar = 5
  def foo(self, x:Int)->String:
    return "hi " + str(x)

b = xyz()
print b.foo(5), b.bar

-------------

In the above code, "a" and "b" have the same interface. We could even go
and declare an interface, specify that the module and the class conforms
to that interface, and then declare a and b to use the interface.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/