You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As discussed on Discord we'd like to add support for a built-in type 'bool' which can only be inhabited by true/false.
Improvements:
We would like programmers to increase their compile-time expressiveness by asserting that a certain variable can only be inhabited by true or false.
Expressions using boolean operators such as ==, && or ! will produce a boolean value.
Problems:
The values 'true' and 'false' are already defined as constants in Daedalus (with the value 1 and 0 respectively). We can probably just ignore their definition.
Just like in C, statements of the form if (intVar) are used quite frequently. We need to accept passing integers into places where a boolean expression is expected, otherwise we break too much code.
Conversely, booleans will need to be implicitly converted to integers as well, to support code that is currently using integers as a replacement for booleans, e.g. if (intVar == true), where converting intVar to boolean would be incorrect.
If we want to enforce some stricter typechecking, we need an explicit way to convert a boolean into an integer. For now we can provide a built-in function to do so, which becomes a NOP during bytecode creation. For compatibility reasons a daedalus equivalent can be introduced when working with other compilers.
Open Questions:
Do we allow implicit conversion from int to bool when providing parameters for a function? I'd like not to, but this will make refactoring a whole lot more annoying, having to change foo(intVar) to foo(intVar != 0) everywhere. On the other hand, this will make refactoring a lot easier because the compiler will yell at places you have forgot to change/refactor.
Here are some examples, including my thoughts on what should happen internally/at the type level. Examples:
if (intVar == True) True is promoted to an integer, using True = 1 and False = 0.
if (intVar) Because if-statements expect a boolean value, the integer has to be conceptually converted to a boolean with C-like semantics, i.e. 0 => False, everything else => True. We don't have to change anything, though, because that is what Gothic already does anyway.
intVar = True; This should maybe throw a warning or error only in strict mode and convert implicitly in non-strict/compatibility mode.
boolVar = 0; this should always throw an error, because the bool datatype is already opt-in, i.e. we have no legacy code to consider.
Please post any additional thoughts you have and I will try to keep the OP updated.
The text was updated successfully, but these errors were encountered:
As discussed on Discord we'd like to add support for a built-in type 'bool' which can only be inhabited by true/false.
Improvements:
true
orfalse
.==
,&&
or!
will produce a boolean value.Problems:
if (intVar)
are used quite frequently. We need to accept passing integers into places where a boolean expression is expected, otherwise we break too much code.if (intVar == true)
, where converting intVar to boolean would be incorrect.Open Questions:
foo(intVar)
tofoo(intVar != 0)
everywhere. On the other hand, this will make refactoring a lot easier because the compiler will yell at places you have forgot to change/refactor.Here are some examples, including my thoughts on what should happen internally/at the type level.
Examples:
if (intVar == True)
True is promoted to an integer, usingTrue = 1
andFalse = 0
.if (intVar)
Because if-statements expect a boolean value, the integer has to be conceptually converted to a boolean with C-like semantics, i.e. 0 => False, everything else => True. We don't have to change anything, though, because that is what Gothic already does anyway.intVar = True;
This should maybe throw a warning or error only in strict mode and convert implicitly in non-strict/compatibility mode.boolVar = 0;
this should always throw an error, because the bool datatype is already opt-in, i.e. we have no legacy code to consider.Please post any additional thoughts you have and I will try to keep the OP updated.
The text was updated successfully, but these errors were encountered: