#367 Num and subclass question

f00biebletch Thu 2 Oct 2008

Given

Int i = ...
Num num = ...

Why does the following compile:

echo(i * num)

while the following does not:

echo(num * i)

I understand the class rationale, but the lack of symmetry over mult is confusing as an end result.

brian Thu 2 Oct 2008

I agree it isn't ideal, but is really because of two independent features interacting together:

i*num  => i.mult(num) =>  i.mult((Int)num)

So the * shortcut turns into the normal mult method. Then the auto-cast feature doesn't force you to insert the manual Int cast.

So there is really only Int.mult(Int). Num doesn't have a mult method, since we'd have to support contra-variance to efficiently limit Int.mult to only take an Int.

Fan doesn't have the numerical tower like scheme languages.

alexlamsl Thu 2 Oct 2008

Just to add that not all number systems are commutative and associative for addition and multiplication ;-)

Login or Signup to reply.