[Prev][Next][Index][Thread]

Re: Interfaces



Scott McKay <swm@mediaone.net> wrote:
> Rob Myers wrote in message ...
> >
> > Java's interfaces are broken, IMHO! Anything that allows naming
> > clashes whilst disallowing code reuse is a real worst of both
> > worlds solution.  Protocols are used in Dylan instead, aren't they?
>
> Any of the 'define protocol' stuff you might have seen is
> just simple macrology I wrote to collate things that I think
> belong in a first-class interface...
> 
> But I didn't mean Dylan interfaces should be like Java.
> I meant that Dylan needs an object -- let's just call it an
> "interface" -- that collects sets of generic functions into
> this interface.  You can then say a class implements [some
> part of] an interface, and some compile-time (or run-time)
> error gets signalled when you try to make an objects whose
> interfaces are not fully implemented.

ISTM you can get most of the way there with modules already.

Do something like

  define module foo-interface
     create
       bar, baz;
  end module;

To implement the interface, define a new module that uses the
interface:

  define module foo-implementation
    use foo-interface, export: all;
  end module;

And then if you don't implement both bar and baz in the module
foo-implementation, then you get a compile time error. You can
implement as much of the default protocol as necessary in
foo-interface, too. 

I think the only thing Dylan really needs to make this a complete
solution is a way to parametrize modules, a la Standard ML's system of
functors. (Matthias Felleisen's units system for DrScheme might also
be worth stealing^H^H^Hlooking at, since it's basically functors for
dynamically typed languages.)

If you want to add types to the interfaces, then I think you'd have to
add parametric types (like Cecil, Eiffel, or GJ) to keep the interface
from becoming a stratjacket that blocks reuse.


Neel



Follow-Ups: References: