Operator Methods
Types can have operator methods. Operators always follow the same precedence and must be immutable.
Operators
- Add (+Add)
- Positive (+Positive)
- Concat (+Concat)
- Subtract (-Sub)
- Negate (-Neg)
- Index ([])
- logical/bitwise (and, or, not, xor, nor)
- bit (<< >>)
One type cannot define both Concat and Add/Positive.
I'm not sure about type enforcement. It would be clean to say that both inputs to an operator must be the same time (what V does). But that doesn't always work, for instance, you can't add two points. So it might make more sense to have Mathematical compliance. So you must have the following consistency
- A+B=C
- B=C-A
- A=C-B
And probably more into multiplication and exponentiation.
For many of these types, function can return two values. For instance on +, the second value is an ok that will return false if the addition overflowed the type.