Nullable or Optional? Or something else?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Sep 2 13:55:53 PDT 2009


Danny Wilson wrote:
> Op Wed, 02 Sep 2009 22:20:04 +0200 schreef Andrei Alexandrescu 
> <SeeWebsiteForEmail at erdani.org>:
> 
>> Jarrett Billingsley wrote:
>>> On Wed, Sep 2, 2009 at 4:13 PM, Simen 
>>> Kjaeraas<simen.kjaras at gmail.com> wrote:
>>>> Danny Wilson <bluezenix at gmail.com> wrote:
>>>>
>>>>> Op Wed, 02 Sep 2009 21:39:28 +0200 schreef Andrei Alexandrescu
>>>>> <SeeWebsiteForEmail at erdani.org>:
>>>>>
>>>>>> I plan to add a Nullable struct to Phobos (akin to C#'s Nullable, 
>>>>>> Boost's
>>>>>> Optional).
>>>>>>
>>>>>> Apparently a good design is to define Optional!T with a minimum of 
>>>>>> member
>>>>>> functions (ideally none) and have it use the "alias this" feature to
>>>>>> masquerade as a T. That way Optional!T looks and feels much like a 
>>>>>> T, except
>>>>>> that it supports a function
>>>>>>
>>>>>> bool isNull(T)(Optional!T value);
>>>>>>
>>>>>> Am I on the right track? If so, what is the name you'd prefer for 
>>>>>> this
>>>>>> artifact?
>>>>>>
>>>>>>
>>>>>> Andrei
>>>>>
>>>>> How about:  Maybe!T
>>>>>
>>>>>
>>>>> Got that from Haskell :-)
>>>> I also feel the bikeshed should be colored 'Maybe'.
>>>  Thirded!
>>
>> Great. Now, before we get all jolly about Maybe, let me point out that 
>> we also need the "ref" corresponding type. And OptionalRef and 
>> NullableRef may sound better to some than MaybeRef.
>>
>> Andrei
> 
> So if pointers wouldn't be considered evil,  Maybe!T*  would suffice?
> 
> Can someone point me out what the big difference is between ref and 
> simply disallowing pointer arithmitic?  Is it marketing?

Ref means lvalue of type T. Pointer is a type distinct from T. So 
although NullableRef!T is substitutable for an lvalue of type T, 
Nullable!(T*) is not.


Andrei



More information about the Digitalmars-d mailing list