Operator Functions

Let's learn how to create our own operators in ReasonML.

We'll cover the following

In Reason, we can use functions to create our own customized operators. The purpose of the operator will be defined within the function.

All the predefined in-fix operators can be used to create new in-fix operators. The same goes for prefix operators.

The Logic

Let’s go back to operators for a bit. An operator is used with a value or values to produce an output. If we consider the operator symbol as the function name and the value(s) as arguments, an operator follows the conventions of a function.

In fact, operators are functions. This implies that we can create our own operators just like we can create our own functions.

The Template

Below, we can see that the template for creating operators is almost identical to that of functions:

Get hands-on with 1400+ tech skills courses.