- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
add 2 argument Nullable constructor #11576
Conversation
LGTM |
Any reason you chose |
One argument is that it matches the storage order, but that's kind of an accident due to how we're using |
we should probably make that change anyways. otherwise, for certain classes of large-ish immutable types
but this PR also seems to be an odd usage of Nullable. does it really make sense to have a two-argument constructor? that seems like a bad abuse of the type, since now you have an instance where |
One potential use case for the two-argument constructor: doing construction without a branch. |
I don't see why having |
It may be worthwhile to add language support for |
I would love to have more language support for Nullables. I suspect we'll need a lot more built-in language support if we want to resolve things like #9446. |
Sounds good, the idea to be able to represent |
while that would allow you to use a slightly small gc sizeclass ( Lines 1115 to 1123 in 4a313de
unless you had some other idea for why this would be useful? |
7e3eb2a
to
007e34f
Compare
Well, I rewrote the code to switch the argument order, but obviously it fails due to the issue @StefanKarpinski mentioned. Is there any way around this? |
One other reason for exposing the 2 argument version (with argument order matching the field order) is that it would allow use of general metaprogramming tricks like this. |
How about using this version: immutable Nullable{T}
isnull::Bool
value::T
Nullable() = new(true)
Nullable(value::T, isnull::Bool=false) = new(isnull, value)
end The storage order is just an internal detail – you'd have to write some very non-abstract code to expose the fact that the |
That suggestion is good by me. |
83cee7b
to
c1e5ce6
Compare
Okay, updated. |
LGTM. |
add 2 argument Nullable constructor
Would be nice to have this documented |
Arose in #11522, but probably good to have generally.