Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible 'bool' type for NOLOL #51

Open
Woccz opened this issue Jun 15, 2021 · 1 comment
Open

Possible 'bool' type for NOLOL #51

Woccz opened this issue Jun 15, 2021 · 1 comment
Labels
backlog Good idea but bad effort to value ratio right now enhancement New feature or request nolol Issues only regarding NOLOL

Comments

@Woccz
Copy link
Contributor

Woccz commented Jun 15, 2021

In addition to #48.

Possibly add a bool type, used to differentiate truthy number variables from number variables used for arithmetic.
This would allow for more optimisations in the future and could raise errors when num type variables are used for logic, and when bool type variables are used for arithmetic.

This would mean code such as

Num x = 3
if x then ... end

would not be valid, however,

Num x = 3
if x != 0 then ... end

would be.

Any if x != 0 then ... end can still be compiled to if x then ... end.

Vise versa, bool type variables should not be allowed to be used for arithmetic, as the value in them is only defined by zero or non-zero.

All comparisons and logical expressions should return a bool type.

This way, if the programmer wants to perform boolean arithmetic, for example, x += a or b, they will have to explicitly state this, i.e. x += (Num)(a or b).
This will let the compiler know that a or b cannot be optimised to a+b, as the programmer wants the 0 or 1 number value, as opposed to the boolean truthy value of a+b.

(Optionally, bool values could be used for arithmetic without casting or errors raised, and instead, detect arithmetic performed on bool values and eliminate any arithmatic optimisations used.)

Thank you.

@Woccz Woccz added the enhancement New feature or request label Jun 15, 2021
@dbaumgarten dbaumgarten added the nolol Issues only regarding NOLOL label Jun 15, 2021
@dbaumgarten
Copy link
Owner

Yes, there absolutely should be a bool-type.
Wheter or not to allow arithmetics with bools remains to be decided.
I am always for maximum type-safety. But in this case it could get annoying really fast. It's probably something to just try out and test how it feels.

@dbaumgarten dbaumgarten added the backlog Good idea but bad effort to value ratio right now label Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Good idea but bad effort to value ratio right now enhancement New feature or request nolol Issues only regarding NOLOL
Projects
None yet
Development

No branches or pull requests

2 participants