-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Feature Request: Bool <: Boolean #23488
Comments
Do you actually need to use these custom types as booleans in Julia code? Converting them to |
Another problem is that you probably wouldn't be able to use it in conditional control flow (e.g. For interoperability with C or Fortran libraries, defining a new I don't think this is going to happen, unless there is a very convincing use case. |
Interoperability with other libraries does not only entail calling into a library, but also the data itself - sometimes gigabytes of data. Practical examples could be the large variety of finite element or CFD solvers, pre- and post-processing tools, lots of other legacy and proprietary mathematical or engineering software. I find it curious that, despite its fundamental importance, And, you're right with the 'Boolean context' of |
I frequently run into the problem of having to define a custom boolean type with an alternative underlying representation. For instance a 16 or 32 bit wide boolean as in Fortran, or a boolean where true and false are not represented by 1 and 0, respectively. These typically originate in external libraries written in other languages...
This feature request aims at providing a customization point in the standard type hierarchy for that.
Thus, I'd like to propose to
The abstract type Logical (or Boolean) should then probably define a minimal interface for testing for true and false, say functions
istrue(x::Logical)::Bool
,isfalse(::Logical)::Bool
. I'm thinking here in particular of the requirement of aBool
in the condition of e.g. a for loop. But this could be decided in the future.Furthermore, there are more logical algebras than just the binary state boolean algebra. Think about the tri-state (true, false, neither), or the four-state (true, false, neither, both). I do not want to propose to add these to base, but, again, to provide a natural customization point in the standard type hierarchy. Thus, those types could find a home as subtypes of
Logical
.While I personally would also prefer a boolean not being a subtype of Integer, these additional abstract types would allow to circumvent that, hopefully, in allowing to define a user-defined alternative bool which does not allow or implement operators +, -, *, ^ etc..
Some relevant issues: #19168, #18367
The text was updated successfully, but these errors were encountered: