gleam
gleam copied to clipboard
Boolean in Bit Strings
It'd be cool to support 1 -> True
and 0 -> False
(and vice versa) in bit string patterns and values.
Maybe, though I worry that there's not a universal binary format for bools. How should they be encoded?
So, I was thinking only of this case:
<<0:1> -> False
<<1:1>> -> True
Also, the syntax could probably benefit most boolean encodings. For example, if you happen to encode a boolean as a byte, you could match on <<0:unsigned-int-size(7), my_flag:bool>>
I've asked on twitter and it seems we're split between <<0:1>>
and <<0:8>>
. Erlang uses <<0:8>>
1> erlang:term_to_binary(1).
<<131,97,1>>
2> erlang:term_to_binary(0).
<<131,97,0>>
<<b1:bool-size(1)>>
<<b2:bool-size(8)>>
Let's have it default to 1 byte
Closing as this hasn't been asked for in a while and the alternative is easy.