does OCaml support infix functions defined in plaintext ?
arg1 `plus` arg2 = arg1 + arg2
thanks
does OCaml support infix functions defined in plaintext ?
arg1 `plus` arg2 = arg1 + arg2
thanks
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
The base language doesn't support infix operators that are identifiers.
You can use ppx to make more or less arbitrary extensions to the syntax of OCaml, but this isn't something to be done lightly (IMHO).
Here is a page with links to ppx info: https://ocaml.io/w/PPX
© 2022 - 2024 — McMap. All rights reserved.
land
,lor
,lxor
,lnot
,lsl
,lsr
,asr
,mod
, andor
as infix operators, but you can't define your own – Depilate