Bitmask/set type ================ It would be nice to have a bitmask/set type. How should it work? Alternative 1: Simliar to an enum --------------------------------- It could work similarly to the enum type: # Which keyword to use? type FileMode = set uint16 { type FileMode = bitmask uint16 { type FileMode = bits uint16 { read write truncate append exclusive_create } Like enums, bitmasks can be extensible/open or frozen/closed to further addition of new values. There should be bitmask operations also. Which syntax to use? var FileMode fm # Flag addition fm = .write + .append fm += .append fm = .write with .append fm = .write and .append fm = .write | .append fm |= .append fm = .write or .append fm = .combine(.write, .append) fm = .write.with(.append) fm = .[.write, .append] # Flag removal fm = fm - .append fm -= .append fm = fm without .append fm &= ~.append fm = fm.without(.append) Alternative 2: Similar to a struct ---------------------------------- # Which keyword to use? type FileMode = set uint16 { type FileMode = bitmask uint16 { type FileMode = bits uint16 { read write truncate append exclusive_create } Like structs, bitmasks can be extensible/open or frozen/closed to further addition of new fields. (Open bitmasks can only be passed by reference outside of their module of definition) var FileMode fm bool should_append # Constructing a value fm = (.write, .append) # Constructing a value with one variable field fm = (.write, .append=should_append) # Setting individual fields fm.write = true fm.append = false # Field operations var FileMode fm1 var FileMode fm2 var FileMode fm3 var FileMode res # bitwise "and" operation. Decide one a syntax res = .common(fm1, fm2) res = .common(fm1, fm2, fm3) # how to support this? res = fm1 bitand fm2 bitand fm3 res = fm1 intersection fm2 intersection fm3 # bitwise "or" operations res = .merge(fm1, fm2) res = .merge(fm1, fm2, fm3) # how to support this? res = fm1 bitor fm2 bitor fm3 res = fm1 union fm2 union fm3 Related: Disallow bitand/bitor/bitxor etc on signed integers?