simit
simit copied to clipboard
Automatic type casting (int->float)
Right now Simit is very particular about the type of literals, and does not automatically cast floats to ints. This results in a type error for this code:
a : float = 1;
Obviously we want to assign 1.0
to a
, but the type checker reports an error because I am trying to assign an integer to a float.
Based on a conversation with @DannyKaufman it might be preferable to keep the current prickly syntax to force programmers to be exact. The casting also raises tricky inference questions. For example, if a vector is inferred to be an int, should it then be auto-casted to float (an expensive operation) as in:
a = [1 2];
b = [1.0, 2.0];
c = a + b % Is this allowed? What's the type of c?
One option is to only allow casting of scalars, but then you have to declare the type of float vector literals that are initialized using scalar:
a : vector[2](float) = [1 2]; % Declare type to force scalar type casting
which is not very satisfying.
Is the plan then to add support for some set of type conversion intrinsics that programmers can use to do type conversion manually? That'd be needed for something like this for example:
var a : vector[5](float);
for k in 0:5
a(k) = k + 1;
end
Explicit scalar casting