I was browsing the Pervasives documentation just now when I encountered a strange “unary addition” operator, which seems at first to be the opposite of the unary negation operator (~-).
val (~+) : int -> int
Unary addition. You can also write + e instead of ~+ e.
Since 3.12.0
When I tested it out, the unary negation operator was pretty straightforward:
# 1;;
- : int = 1
# ~- 1;;
- : int = -1
# ~- (~- 1);;
- : int = 1
But the unary addition operator didn’t seem to make much sense except as an identity operator.
# ~+ 1;;
- : int = 1
# ~+ (~+ 1);;
- : int = 1
# ~+ (~- 1);;
- : int = -1
While the unary negation actually performs a negation, the unary addition operator just seems to do… nothing. Though, I suppose this could makes sense mathematically speaking… given that:
a + (-b) = a - b
However, to me, it does seem a bit out of place in Pervasives. Does anyone know of any actual uses for this operator?