convex
convex copied to clipboard
Should `boolean`, `byte` and `char` coerce to double implicitly?
This is what Clojure does as well, but I am wondering it isn't best to always avoid double coercions.
Do you mean implicitly?
I think implicit widening is OK. Implicit loss of precision should probably be a no-no.
Sorry there, went horribly wrong with the original title!
This is about double, such as (double \a), hence the double conversion Char -> Integer -> Double
I think the answer might be no in general? Multiple sequential conversions don't seem like something we should try to do implicitly, it could be dangerous.
We could make a case for it working with Byte though, since this is really an integer value already. As per #89
I would advocate for no as well to be inline with previous similar decisions.
I think it depends whether we want to count Byte as a numeric type or not.
Generally you can implicitly up-cast to larger numerics, so (+ 1 2.0) would be expected to work (returning a Double which is the "largest" numeric type involved).
So if Byte is numeric, it should implicitly cast to Long and Double. In which case (+ 1.0 (byte 2)) should work, as well as some interesting things like (get [1 2 3 4] (first 0x0203))
If Byte is not numeric, then of course explicit casts would be required to do the above.