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

inherted overload & mixed type operations



I have an interesting problem. I've just implemented PDL::Complex, which
is a subclass of PDL. (PDL is, in short, a vector language).

Now, it is possible to write things like:

5+3*i and get [5 3]. i is a constant of type PDL::Complex (i.e. blessed in
that package).

Since PDL::Complex is overloaded (just as PDL).

However,

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?
b) would it make sense except for obvious cases like complex and real-valued
   types?

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.

-- 
      -----==-                                             |
      ----==-- _                                           |
      ---==---(_)__  __ ____  __       Marc Lehmann      +--
      --==---/ / _ \/ // /\ \/ /       pcg@opengroup.org |e|
      -=====/_/_//_/\_,_/ /_/\_\       XX11-RIPE         --+
    The choice of a GNU generation                       |
                                                         |


Follow-Ups from:
Ilya Zakharevich <ilya@math.ohio-state.edu>

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