F# is very strict with numeric types. There are several reasons for this.
- Precision -
4.0 * 8.5
might not be exactly equal to4*8.5
due to precision loss when converting to floating point. By forcing you to convert4
to4.0
the language has made that precision loss clear Type inference. Functions need to have concrete argument types. If we allowed implicit conversion from
int
tofloat
, it would not be clear what the type ofa
should be in this examplelet test a = a + 1.0
as both
int
andfloat
could be valid types fora
. (This can be avoided through inline functions where there are less restrictions on argument types and by using some functions likegenericZero
andgenericOne
- Simplicity. As there are no automatic type conversions, any conversions are immediately obvious and some mistakes become much simpler to spot.