Operator overhaul

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Oct 21 20:40:01 PDT 2008


bearophile wrote:
> Andrei Alexandrescu:
>> struct Whatever { Whatever opAdd(Whatever rhs) { return member +
>> rhs.member; } Whatever opSubtract(Whatever rhs) { return member -
>> rhs.member; } ... } and lines and lines of brain damaged
>> repetition, repetition, repetition. If we add opWhateverAssign that
>> will get even worse. The challenge is, then, to define a way to
>> overload operators that makes the classic applications of the
>> feature short and sweet.
> 
> I'm a newbie still regarding such stuff.
> 
> At a first sight a possible solution is to resort to mathematics:
> state somehow that class has the property of being a Number, maybe
> Additive too, then such methods become automatically defined for
> free... :-)
> 
> I think functional languages have similar things, it may be named
> structural subtyping... I am too much ignorant about this topics, I
> am sorry. Once I know Haskell well enough I'll be able to talk about
> this stuff much better.

Well it's great you are improving on that kind of knowledge. It's also 
very nice that you acknowledge lack of expertise in the matter 
(something very rare on the Usenet and in this group too) and finally it 
is nice that in the same post you _do_ give advice, which suggests there 
may be a contradiction somewhere :o).

> I suggest you to ask this question in the "Lambda the Ultimate" blog,
> they are quite expert of such matters, and they are very willing to
> help. If you say them you want to make D "more functional" they will
> work for you in the nights too for free :-)
> 
> At the moment D1 has class mixins to do something like that, they can
> find the name of the class by themselves too.
> 
> Bye, bearophile

Our problem is not that we're out of ideas, but instead that there's an 
embarrassment of riches in terms of the particular solution to adopt. 
LtU is an excellent forum populated by many Illuminati, yet sometimes 
discussions could get tedious because they become overly general. For 
example: "I want to do this for D." "Wait, why doesn't D make everything 
a reference? That would certainly make things cleaner" etc.


Andrei



More information about the Digitalmars-d mailing list