-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 a parametric Nullable{T} type #8152
Conversation
👍 Is the error behavior of I think we could get by without |
Yeah, the error behavior was based on my thought that, since we should raise errors when comparing anything with a null value, it's easier to just not try comparing Nullable objects at all than to wait for a run-time error when your equality comparison hits its first null. Agree that we can just use Nullable. |
Once this is merged it's probably worth being very clear in the manual section precisely what the semantic differences are between |
We will have 3 concepts for nothing. Nothing/nothing, None/Void and NullableTypes. Looking forward to make http://docs.julialang.org/en/latest/manual/faq/#nothingness-and-missing-values even more complicated. |
Right, I forgot about None and Void. |
I wonder if |
Well, it's a collection with zero or one element. Perhaps it should be
|
I find the name slightly misleading, as a nullable value is immutable and as such can not be nulled after construction. I re-read rapidly the thread on julia-users, and I'm not sure if the question of supporting both "ontological/statistical missingness" as been decided. But if |
With the view of container with 0-or-1 elements, I would personally find |
Regarding |
The main advantage of I don't think an Option type or this Nullable type can or should specify exactly what value-missingness means. It's for any case where there could be a value, but there isn't one right now. In C# The name |
I actually very much like our choices of names for None, Nothing and nothing and have found that people are mostly not confused by them since they are so semantically apt. Perhaps Python should change it's naming instead ;-) |
Regular expressions matching would be another good target for this once On Wednesday, August 27, 2014, Stefan Karpinski notifications@github.com
|
Yes the names are apt, but I have seen people use |
Responses to various comments:
|
I agree with the choice of Nullable as most intuitive to the most people. Option is a weirdly broad term that only suggests the right meaning to a very small set of people who will be using this. |
529893b
to
4078c04
Compare
Updated:
|
I think the fact that |
+1 to John's responses. I kind of like the idea of using only |
+1 to |
|
If we change the meaning of |
Here's an interesting idea: rename
|
I like the mix of |
So |
That's a fair point --- in the case of Interestingly the following C code seems to be legal:
This compiles, runs, and doesn't segfault. So giving |
4078c04
to
f983e0e
Compare
Updated with a draft of a manual section. I'm really bad with RST, so please make sure I haven't done anything very stupid. In particular, I'm worried about the interaction of |
So, I'm a bit concerned that |
I also think |
I think that's a good argument for @eschnett's proposed solution. |
@JeffBezanson, note my proposal was If we go with the julia> NullableTypes.Null{T}(x::T) = Nullable{T}()
Null (generic function with 2 methods)
julia> Null(1)
Null(Int64)
julia> Null(Int)
Null(Int64) |
You seem determined to introduce some The danger here is that The function |
No, that makes sense. Particularly the arguments for simplicity and the power of Nullable. I'd vote then to go with the |
I had argued for this change before: I think it would be better to have a consistent convention for |
It's probably way too late in the discussion to bikeshed the name of the type... I don't like the name
Haskell calls this type I like |
+1 for consistency and |
@eschnett I agree with everything you've said in this thread, including that it is too late to bikeshed the name :) I'm actually not particularly attached to |
@eschnett I think one of the points in favor of the |
The term "Nullable" indicates that there is some kind of operation that the object supports, namely "nulling" it. This does not really indicate that (a) there is a function I guess we come from different programming language backgrounds. When I compare https://en.wikipedia.org/wiki/Nullable_type and https://en.wikipedia.org/wiki/Option_type, then I'd place Julia firmly in the latter category... |
I read the Nullable type article, and nowhere does it mention an operation of "nulling" a value. The Option type article says "Outside of functional programming, these are known as nullable types." That seems to mean different kinds of programming have different names for the same thing, not that there are different kinds of option types (e.g. mutable vs immutable). We agree that "X is nullable" does not imply that X supports some mutating operation. Why then would you say that "nullable" implies "nulling", which is a mutating operation? Maybe "nulling" means "constructing a similar value that is null". So I think the term is reasonable, making some allowance for the limitations of human language. |
FWIW, I think the argument about names is not likely to prove fruitful. First off, the English suffix "-ble" does not precommit the earlier morpheme to any specific interpretation: compare livable, visible, defensible, potable, etc. Some of these involve transitive verbs, but some do not. Second off, our type isn't identical to an Option or Maybe, since it's not a tagged union, but a distinct parametric type. This a somewhat minor point, but using a distinct name will help to keep the type theory folks from complaining about the use of terms that they perceive to have highly specialized meanings. |
I agree the naming debate is not very fruitful, I was just starting to enjoy it :) |
With the |
48856b8
to
892e746
Compare
Updated to use |
And Travis gives us the green light. |
Bump. |
Add a parametric Nullable{T} type
🍰 |
This adds a parametric Nullable{T} type that can represent a value of type T that may be missing. It's got a very minimal interface with the hope that this will encourage you to resolve the uncertainty of whether a value is missing as soon as possible.
Work left to do:
I also did a little bit of whitespace removal along the way, which is hopefully forgivable.