This seems like a bug in the compiler - or am I missing something (report it to fsbugs on microsoft dot com ). For some reason, the compiler does not make a built-in call to the + operator (it works for - and / and for custom operators such as +. , But does not work for + and * ).
This means that the compiler really generates something like:
The AdditionDynamic method uses some internal table to search for + implementation for two types at runtime. Although you could register your type there, that would not be very useful, because the call would be slow.
I actually donβt have a good workaround - if you need an operator only for some basic numeric types ( float , int , etc.), then the easiest option would be to simply avoid using inline here and define an (overloaded) operator for specific types:
static member (+) ((x:float,y:float), a: float Test) = x + y + ax + ay
You can also try a trick with a global operator and helper type that implements various overloads, but I'm not sure if this will help: see, for example, this past question .
Tomas petricek
source share