Which language has the biggest…
-
@PleegWat aside - of all the words that could possibly be used for the non-empty value of an option type,
Just
is one of the worst.
-
@Gąska They should have used
Supercalifragilisticexpialidocious
instead.
-
-
@Bulb said in Which language has the biggest…:
@pie_flavor It does not matter whether it is
null
specifically. The problem is with whatever the Nothing variant is.Hmm. But in your example of a list, at no point is anything creating the nested version directly, yes? It's just incidentally nesting because of generics. Your issue relies on the semantics of creating the nested version directly, but if you are creating the nested version directly then you're probably doing it wrong.
-
@pie_flavor not creating. Just reading its value. Even if it's created through generics, reading the value is often done directly. And then, not being able to differentiate between
None
andSome(None)
can be a problem. And sinceNullable
cannot nest, you not only can't create such a value, but also cannot pass a generic parameter to a generic function such that it would result inNullable<Nullable<int>>
through specialization of generic code.
-
@Gąska said in Which language has the biggest…:
@pie_flavor not creating. Just reading its value. Even if it's created through generics, reading the value is often done directly. And then, not being able to differentiate between
None
andSome(None)
can be a problem.But that's not done with implicit conversion, so there is no issue. Differentiating is done with the
HasValue
property.And since
Nullable
cannot nest, you not only can't create such a value, but also cannot pass a generic parameter to a generic function such that it would result inNullable<Nullable<int>>
through specialization of generic code.Which is why we're not talking about
Nullable
anymore butOptional
.
-
@pie_flavor said in Which language has the biggest…:
@Gąska said in Which language has the biggest…:
@pie_flavor not creating. Just reading its value. Even if it's created through generics, reading the value is often done directly. And then, not being able to differentiate between
None
andSome(None)
can be a problem.But that's not done with implicit conversion, so there is no issue.
Then tell me - just what in the hell does implicit conversion do in such case? Because it must behave exactly the same as in case of regular non-nested optional, or else it's going to be even more painful to work with due to irregular behavior (especially inside generic code).
@pie_flavor said in Which language has the biggest…:
Which is why we're not talking about Nullable anymore but Optional.
The discussion here is very hard to follow. Thank you that you clarified this part.
-
@Gąska said in Which language has the biggest…:
@pie_flavor said in Which language has the biggest…:
@Gąska said in Which language has the biggest…:
@pie_flavor not creating. Just reading its value. Even if it's created through generics, reading the value is often done directly. And then, not being able to differentiate between
None
andSome(None)
can be a problem.But that's not done with implicit conversion, so there is no issue.
Then tell me - just what in the hell does implicit conversion do in such case? Because it must behave exactly the same as in case of regular non-nested optional, or else it's going to be even more painful to work with due to irregular behavior (especially inside generic code).
It doesn't.
Optional<T>
doesn't implicitly convert to anything.
-
@pie_flavor oh, okay. So when you said "you're supposed to provide conversions", you didn't mean that an option type is supposed to provide conversion?
-
@Gąska FFS I posted the exact code we're discussing.
T
implicitly converts toOptional<T>
andOptional<T>
explicitly converts toT
.
-
@pie_flavor said in Which language has the biggest…:
@Gąska FFS I posted the exact code we're discussing.
T
implicitly converts toOptional<T>
andOptional<T>
explicitly converts toT
.Didn't this whole discussion start from the observation that it would be a bad idea for
Optional<T>
to implicitly convert toT
, though?
-
@topspin Yes. Which it doesn't. I repeat, I have no idea what the fuck the confusion is here.
-
@pie_flavor said in Which language has the biggest…:
@dkf Okay, but I was talking about in the case of C#. There is no dereference operator to override. I could override operator~, but I don't think that'd be as sensible. You're supposed to provide conversions for things that are conversions, not just things that are convenient.
So what do you project "no value" onto?
-
@Captain Project?
-
@pie_flavor What does "no value" map to in the codomain?
In mathematics, a projection is a mapping of a set (or other mathematical structure) into a subset (or sub-structure), which is equal to its square for mapping composition (or, in other words, which is idempotent).
You're heading into crazy town at high speed if projections aren't idempotent.
-
@Captain You mean what does empty convert to? It'd throw an exception, since the explicit conversion just references the Value property.
-
@pie_flavor Ugh. WOO WOO ALL ABOARD TO CRAZY TOWN.
-
@Captain We're all mad here.
-
@topspin said in Which language has the biggest…:
@pie_flavor said in Which language has the biggest…:
@Gąska FFS I posted the exact code we're discussing.
T
implicitly converts toOptional<T>
andOptional<T>
explicitly converts toT
.Didn't this whole discussion start from the observation that it would be a bad idea for
Optional<T>
to implicitly convert toT
, though?Also that explicit casts are godawful. Especially with nested options.
Unless C# has something that works like
var
in that it automatically guesses the correct type, but you can use it as target type of cast?
-
@Gąska I don't think so, no. You could make a generic function to do that, which can infer the type, but it wouldn't work with conversion operators.
-
@pie_flavor sounds like the problem is conversion operators. The solution is not to care about conversion operators.
-
@Gąska said in Which language has the biggest…:
The solution is not to care about conversion operators.
But on Earth-73, they've got to put the entire functioning of their program in conversion operators!