Article: Writing Julia style multiple dispatch code in D
data pulverizer via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Wed Aug 30 10:16:59 PDT 2017
On Wednesday, 30 August 2017 at 17:14:37 UTC, data pulverizer
wrote:
> On Wednesday, 30 August 2017 at 16:45:19 UTC, data pulverizer
> wrote:
>> You mentioned Julia in your article, however for clarity I
>> would point out that Julia doesn't have OOP-type polymorphism.
>> There is no notion of being able to do something like:
>>
>> Animal snoopy = new Dog();
>
> p.s. my bad, I was wrong about that! Turns out you can do
> something like this in Julia (apologies for the Julia code in a
> D forum):
>
> abstract type Animal end
> struct Dog <: Animal end
> struct Cat <: Animal end
>
> x = Array{Animal}(3)
> x[1] = Cat(); x[2] = Dog(); x[3] = Cat();
> x # returns
> 3-element Array{Animal,1}:
> Cat()
> Dog()
> Cat()
p.p.s
typeof(x[1]) # returns Cat
so it isn't really polymorphism - the object is never converted
to the "parent" type! Lol ... sorry for the confusion!
> Which is polymorphism
More information about the Digitalmars-d-announce
mailing list