[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: inherted overload & mixed type operations



Marc Lehmann writes:
> pdl(5)+pdl(3)*i is evaluated according to the PDL-multiplication,
> presumably because perl always uses the type of the first (lefthand)
> operator.
> 
> In that case, it would make sense to always use PDL::Complex's
> multiplication, on the assumption that a subclass always knows better.
> 
> So my question I want to propose is two-fold
> 
> a) would it be (computationally) feasible to detect this case and use
>    the subclass operator always?

Yes.  PDL overloaded multiplication can (and should) do it.

> b) would it make sense except for obvious cases like complex and real-valued
>    types?

Polymorphism by two arguments is always a tricky topic.

> BTW, "use overload" automatically inherits all the ops from its
> superclass, which is not always a good thing: I do not want to
> inherit >=, > etc.. but instead want to perl to synthesize it from my
> <=>-operator. Unfortunately, doing ">" => undef does not do that.

This is an interesting topic...  Specify 'fallback'-per-optype?

Ilya


Follow-Ups from:
Marc Lehmann <marc@gimp.org>
References to:
Marc Lehmann <marc@gimp.org>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]