Representing Nullable Values

Good question. I think it comes down to the line of reasoning that, if it’s not required, then you can’t rely on it being present, but then you can’t do anything with it, so why is it there? Indeed, the small union optimizations will work for this case also, but the runtime cost is a bit higher, since there’s an extra level of unwrapping that the runtime must do (It’s effectively now Union{Value{T}, Null{T}, Null{Union{}}})

The naive memory layout of Array{DataValue{T}} would also suffer greatly compared to Array{T?} (since it is interspersing the data with the nullable bit), but it sounds like you know that already, from your mention of DataValueArray and NullableArray as mechanisms for separating the two fields (data and null bit).

1 Like