4 ms·
(+) is an operator that takes 2 ints and produces an int (+.) is the equivalent for floats: 1.0 +. 1.0 In short: if you need any operator for floats, and you
by toolslive 8y ago
(+) is an operator that takes 2 ints and produces an int
(+.) is the equivalent for floats: 1.0 +. 1.0
In short: if you need any operator for floats, and you know how to write it for ints, add a dot.
The reasoning is that it's hard to define the semantics of mixed expressions and explicit conversions clarify what needs to happen.
- dpwm 8y agoI initially hated the separate operators for floats and integers. I've since grown to like it, because the only times I've been caught out by it is when I've made a mistake or I've forgotten I was working with floats. Don't let the syntax put you off Ocaml, because there is some reasoning behind it. It's a multi-paradigm language that has a lot of powerful features.
- gpderetta 8y agoNot allowing mixed expressions is completely orthogonal to using the same symbols for float or integer (or bignum or fixed or...) addition.
- zeroname 8y agoThe non-obnoxious solution for that not-so-big problem is explicit conversions, not a whole new set of ugly multi-character operators.