The problem with Nullable: nullable(null).isNull is false.
Paul Backus
snarwin at gmail.com
Tue Jul 26 15:34:20 UTC 2022
On Tuesday, 26 July 2022 at 15:21:36 UTC, jfondren wrote:
> On Monday, 25 July 2022 at 13:05:08 UTC, Steven Schveighoffer
> wrote:
>>
>> The real "problem" is that Nullable is called "Nullable".
>>
>
> History of this poor type:
>
> 1. it's a way to add a Null state to a value type. You know,
> like Java. Very convenient type for trivial task.
>
> 2. hey! This doesn't act like an optional type/maybe monad!
> This is BROKEN. (convenience was deliberately broken to make it
> worse for the original task.)
>
> 3. hey! This acts like an optional type/maybe monad that
> doesn't care if the wrapped type also has something like a null
> state! This is BROKEN. (now proposed: deliberately break it to
> make it worse as an optional type.)
This makes for a nice story, but doesn't actually match the
facts. Since it was introduced in 2009 [1], `Nullable` has always
had a distinct `isNull` state, even for types that can already be
`null`.
[1]
https://github.com/dlang/phobos/commit/0c142994d9#diff-81bed7f05cbd4e992067b7019125e6a1349ebe5098c6980b64bbbca8d5491e17
More information about the Digitalmars-d
mailing list