does OCaml support infix functions defined in plaintext ?
arg1 `plus` arg2 = arg1 + arg2
thanks
A custom prefix operator can made by from a ! followed by one or more symbol characters. and is followed by one or more symbol characters. For example let ( ~! )
User defined infix function notation –It must be member function or extension function. It must accepts a single parameter. The parameter must not accept variable number of arguments and must have no default value. It must be marked with infix keyword.
An infix operator is a function of two arguments, with the name of the function written between the arguments. For example, the subtraction operator - is an infix operator.
There's no way to define a function with an alphanumeric name as infix. Haskell's syntax rules only allow for functions with symbolic names or function names surrounded with backticks to be used infix - there's no way to change that.
No. As explained in the OCaml manual, infix operators can only contain special characters, namely !
, $
, %
, &
, *
, +
, -
, .
, /
, :
, <
, =
, >
, ?
, @
, ^
, |
, ~
(or #
but only in first position) and must not start with !
, ?
or ~
.
In order to define an infix operation, you must put the symbol into parentheses:
# let (+++) x y = x + 2 * y;;
...
# 3 +++ 4;;
- : int = 11
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With