On 2016-02-06 14:33:57 +0000, Marc Schütz said:

I don't see why this wouldn't work, if you've in fact covered all combinations.

It works, the problem was that castSwitch returns something and I didn't "catch" it.

It's similar to how castSwitch is implemented, though the double casts are inefficient. You could use:

if(auto inta = cast(IntV) a) {
     if(auto intb = cast(IntV) b) {
         return new IntV(inta.num + intb.num);
     }
}

Yes, thanks. Was on my list.

(Again, this can be automated.)

How? Do you mean by castSwitch?


I read this here: https://github.com/D-Programming-Language/phobos/pull/1266#issuecomment-53507509 (functional pattern matching) but it seems it won't be implemented... at the end of the day what I simulate are poor-mans-multimethods

As I read the discussion, it was just decided to defer the more complex version of castSwitch for later, but it wasn't rejected.

Well... yes, "won't be implemented in the near future" Anyway, it's not available at the moment, so looking at other ways.

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

Reply via email to