Virtual opBinary in interface
sfp
sfp at hush.ai
Sat Dec 21 23:14:14 UTC 2024
On Friday, 20 December 2024 at 18:40:17 UTC, Ali Çehreli wrote:
> On 12/19/24 10:49 AM, sfp wrote:
> > Subject lines says it all
>
> Although you clearly have a need for, virtual operators haven't
> been common in my experience. I always felt they could cause
> semantic issues.
>
> ...
>
> But it uses his magical implementation (enabled by D) of open
> methods (and multi-methods).
>
> Ali
Right, the semantics can be a little odd, but there are
definitely use cases for it which are very natural. Modeling how
different kinds of animals mingle, I'm not sure... :-)
"Virtual binary operators" are quite useful in computational
science (my field...). For instance, with a numerical linear
algebra library, you might have sparse matrices, dense matrices,
diagonal matrices, Toeplitz matrices, matrices which are only
accessible indirectly via their action (e.g. you multiply with a
discrete Fourier transform matrix by applying the FFT and do not
store the matrix itself), *block* matrices (comprised of other
matrices), etc, etc.
It is pretty common to mix and match these heterogeneously.
MATLAB and Python have dense and sparse matrices, potentially
other user-defined matrices/operators, and mixing and matching
them is straightforward. Duck-typing is especially nice here,
because there is no need to return a super type... multiply a
dense matrix with a diagonal matrix and return a dense matrix
(rather than a matrix supertype), no problem...
I actually saw this multimethod implementation in another forum
post when searching around, but not the talk. Thanks for posting
it. I will definitely take a look, but unless I'm mistaken, D
doesn't have free binary operators?
More information about the Digitalmars-d-learn
mailing list