On Wednesday, 30 August 2017 at 20:40:38 UTC, Jean-Louis Leroy wrote:

After mulling over this example, I don't see how this proves that Julia does *not* support run time polymorphism. On the contrary. If you translate this to D you get the same result by the way:

import std.stdio;

class Animal {}
class Cat : Animal {}

void main()
  Animal[] array;
  array ~= new Cat();
  writeln(typeid(array[0])); // typeid.Cat

writeln(typeof(array[0]).stringof); // this is an Animal

The return type of any item in the array would be of type Animal. You would have to do a type cast to really get type Cat.

In Julia there is no real notion that any item in Array{Animal, 1} is an Animal. Their types are never masked by Animal, which only really serves as a way of dispatching types to the array, unlike in D where the actual type is Animal. However if your multi-methods is dispatching methods using typeid (which I am guessing is the case) this distinction no longer matters.

It may be better to say that typeof() in Julia is a run-time type and there is no notion of typeof() as in D.

In the light of this I think your package just became more interesting to me.

Reply via email to