|
|
|
|
|
by ReleaseCandidat
1055 days ago
|
|
> It looks simple but in a typed language it's actually somewhat tricky. But that example looks about as simple as it can be, so I clearly must miss something. > The compiler needs to infer that the 1 is a float type, 2 is a byte, and compile it appropriately. And I don't understand _why_ it has to infer anything, as the type is explicitly declared.
I mean, there are 2 possibilities:
* 1 is both a valid integer and a float literal => Nim needs the type declaration on the left to unify the type (from "integer or float" or "numeric" or whatever the type checker inferred) to `float`.
* 1 is not a valid float literal (but an integer) => the type is not inferred, but implicitly converted to `float`.
In both cases the solution does not involve inference? |
|