Dear community,
I have a problem and my preferred solution does not work:
- Problem:
There is a C# library with an overloaded == operator gurobi 9.1. I want to use this operator in F#, such as in
let setEqual (lhs : GRBLinExpr, rhs : GRBLinExpr) =
GRBLinExpr.(==) (lhs, rhs)
This fails with “FS0039 The type ‘GRBLinExpr’ does not define the field, constructor or member ‘==’.”
Also addressing it as member op_EqualsEquals as outlined in F# ops does lead to the same error.
- Extra information: Adding the library to a C# project shows me:
public static Gurobi.GRBTempConstr operator ==(Gurobi.GRBLinExpr lhs, Gurobi.GRBLinExpr rhs)
Member of Gurobi.GRBLinExpr
)
and the following compiles
static GRBTempConstr SetEqual(GRBLinExpr lhs, GRBLinExpr rhs)
{
return lhs == rhs;
}
- Possible workaround: I can create an extra C# project, wrap the == operator there in a static method and reuse this method in F#. Pro: Works. Cons: extra project.
So my questions are:
a) Why does F# not allow me to use this operator? Are there some limitations to using operators from F#? The F# docs does not mention any (sorry, see “F# ops” link above, as this forum does not let me post the same link twice :-() .
b) Are there other workarounds than 3)? Maybe with reflection?
Cordially,
htc