True and False types?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

True and False types?

Diego Javier Zea
Hi!

Maybe it's a silly question... Could be possible to define bool values as immutable types instead of using an 8 bits bitstype?

Something like

abstract Bool
immutable True <: Bool end
immutable False <: Bool end

instead of 

bitstype 8 Bool <: Integer

I believe it would be cleaner than using true, false, Val{true} and Val{false}

Best,
Reply | Threaded
Open this post in threaded view
|

Re: True and False types?

Yichao Yu
On Sun, Mar 13, 2016 at 1:59 PM, Diego Javier Zea <[hidden email]> wrote:

> Hi!
>
> Maybe it's a silly question... Could be possible to define bool values as
> immutable types instead of using an 8 bits bitstype?
>
> Something like
>
> abstract Bool
> immutable True <: Bool end
> immutable False <: Bool end
>
> instead of
>
> bitstype 8 Bool <: Integer
>
>
> I believe it would be cleaner than using true, false, Val{true} and
> Val{false}.

No, for one thing a Bool member will take a pointer size and not 1
byte. It is also almost always a bad idea to represent something with
a type rather than a value when it is common for a variable to take
different values (the variable will be type unstable, passing it to a
function leads to over specialization or dynamic dispatch).

>
> Best,