I am writing a tiny matrix library (mostly shell methods) in F # and have the problem of overloading static operator methods, with F # choosing the overload that I did not intend for it.
I have a module where I determined the correct matrix multiplication with a vector:
[<AutoOpen>]
module MatrixOps =
let (*) (matrix : IMatrix) (vector : IVector) =
(...)
This allows me to write things like A * v, for example, where A is IMatrix and v is IVector. However, now I am adding the following line below let-binding:
let z = 1.0 * 2.0
and then the F # compiler identifies this as an error. Hover over "1.0", I get: "Type" float "is incompatible with type" IMatrix ", and similarly, hovering over" 2.0 ", I get:" Type "float" is incompatible with type "IVector". What happens here It seems that the F # compiler does not apply the multiplication operator for float and instead applies the operator for IMatrix and IVector. If I write instead
let z = (1.0 : float) * (2.0 : float)
the problem persists, so adding explicit type annotations does not help. How can I guarantee that F # selects the floating multiplication operator instead of the IMatrix / IVector operator defined above?
source
share