[Grace-core] Multiple inheritance & module inheritance

Timothy Jones tim at ecs.vuw.ac.nz
Sun Mar 15 18:15:06 PDT 2015


On 10/03, Kim Bruce wrote:
> Reading between the lines, I'm guessing that you are worrying about foo and
> bar both being defined inside another object (call it baz), and that we could
> define another object by inheriting from baz and then overriding foo. (This
> seems to be leading us to "family polymorphism" kind of issues.)
> 
> Is that the concern?  If so, could you provide a full example that shows the
> problem?

So, for something to discuss tomorrow, here's an example of how
'statically-known' as a requirement on inheritance doesn't really make sense:

  def module = object {

    class a.new {
      def x = 1
    }

    class b.new {
      inherits a.new

      def y = x + 1
    }

  }

If the module is inherited through delegation/cloning/whatever mechanism, the
inheritor can override the class 'a', with changes like removing 'x' or not
being inheritable at all.

  def module' = object {
    inherits module.clone

    method a {}

    b.new
  }

So 'a.new' is not statically-known, and this inheritance is not valid. All
methods have to be defined in objects, so the only things that it's possible to
inherit from are classes defined inside of methods or blocks:

  {
    class a.new {}
    class b.new { inherits a.new }
  }

This is something the 'let' proposal was able to solve: classes can't be
overridden, and so they can always safely be inherited from.

-- 
Tim


More information about the Grace-core mailing list