property na : Integer = 2
property nb : Integer = 3
property ra : String
function plus(left : Integer, right : Integer) : Integer
do
return left + right
end
function isFiveAsString(maybeFive : String) : Integer
do
return maybeFive == "5"
end
ra = plus(na, nb)
print isFiveAsString(ra)
The example looks a bit constructed, but I ran into this issue while doing some work. Right now ThingML allows implicit conversion of types, which works great for numbers (or could possibly be problematic if mixing floating points and integers (3 is not always 3)). In this case I have a function (isFiveAsString) which accepts a string as an argument, checks it against a string ("5"), but it will return false. The ra property, although declared as a string, is a number, since it was created as an addition between to numbers.
I'm not sure if allowing implicit type conversion is a good idea in the long run. Maybe it is something at the very least should be possible to disallow when defining a type?
Pseudo-code
The example looks a bit constructed, but I ran into this issue while doing some work. Right now ThingML allows implicit conversion of types, which works great for numbers (or could possibly be problematic if mixing floating points and integers (3 is not always 3)). In this case I have a function (isFiveAsString) which accepts a string as an argument, checks it against a string ("5"), but it will return false. The ra property, although declared as a string, is a number, since it was created as an addition between to numbers.
I'm not sure if allowing implicit type conversion is a good idea in the long run. Maybe it is something at the very least should be possible to disallow when defining a type?