Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you define an operator (***) in F#?

I'm working on Arrows in F# and I wanted to create a *** operator. I note, however, that (***), the necessary way to express an operator in a function definition, overlaps with the F# block comment syntax. So how could you actually express this?

I thought of maybe .***. but I think that will actually treat the dots as part of the operator, which I'd rather avoid.

like image 753
CodexArcanum Avatar asked Oct 26 '10 20:10

CodexArcanum


People also ask

How do you declare an operator function?

You declare an operator function with the keyword operator preceding the operator. Overloaded operators are distinct from overloaded functions, but like overloaded functions, they are distinguished by the number and types of operands used with the operator. Consider the standard + (plus) operator.

What is an operator function in C++?

An operator function is a user-defined function, such as plus() or equal(), that has a corresponding operator symbol. For an operator function to operate on the opaque data type, you must overload the routine for the opaque data type.

How do you define operator overloading in C++?

Operator Overloading in C++ This means C++ has the ability to provide the operators with a special meaning for a data type, this ability is known as operator overloading. For example, we can overload an operator '+' in a class like String so that we can concatenate two strings by just using +.

What operators Cannot be overloaded in C++?

Operators that cannot be overloaded in C++ For an example the sizeof operator returns the size of the object or datatype as an operand. This is evaluated by the compiler. It cannot be evaluated during runtime. So we cannot overload it.


1 Answers

Yes, but you need to add spaces between the parentheses and the asterisks:

let ( *** ) x y = x * y

let z = 4 *** 5
like image 56
kvb Avatar answered Nov 09 '22 13:11

kvb