Google News
logo
F# - Interview Questions
What is Operator Overloading in F#;
This topic describes how to overload arithmetic operators in a class or record type, and at the global level.
 
Syntax :
// Overloading an operator as a class or record member.
static member (operator-symbols) (parameter-list) =
    method-body
// Overloading an operator at the global level
let [inline] (operator-symbols) parameter-list = function-body
In the previous syntax, the operator-symbol is one of +, -, *, /, =, and so on. The parameter-list specifies the operands in the order they appear in the usual syntax for that operator. The method-body constructs the resulting value.
 
Operator overloads for operators must be static. Operator overloads for unary operators, such as + and -, must use a tilde (~) in the operator-symbol to indicate that the operator is a unary operator and not a binary operator, as shown in the following declaration.
 
static member (~-) (v : Vector)
Advertisement