Thread overview | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 10, 2013 Option!T | ||||
---|---|---|---|---|
| ||||
I talked to a programmer who knows Scala (among others) and he mentioned the usefulness of the Option type - a zero or one element collection (range in D terminology). Here's an article discussing it: http://danielwestheide.com/blog/2012/12/19/the-neophytes-guide-to-scala-part-5-the-option-type.html We have only(x) (http://dlang.org/phobos/std_range.html#.only) to be a collection of exactly one value, but not a type for "a value of type T or nothing at all". Should we follow Scala's example and add it? Andrei |
December 10, 2013 Re: Option!T | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Tuesday, 10 December 2013 at 17:28:26 UTC, Andrei Alexandrescu wrote:
> We have only(x) (http://dlang.org/phobos/std_range.html#.only) to be a collection of exactly one value, but not a type for "a value of type T or nothing at all".
Is this not what Nullable!T is?
|
December 10, 2013 Re: Option!T | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 2013-12-10 17:28:26 +0000, Andrei Alexandrescu said:
> I talked to a programmer who knows Scala (among others) and he mentioned the usefulness of the Option type - a zero or one element collection (range in D terminology). Here's an article discussing it: http://danielwestheide.com/blog/2012/12/19/the-neophytes-guide-to-scala-part-5-the-option-type.html
>
>
> We have only(x) (http://dlang.org/phobos/std_range.html#.only) to be a collection of exactly one value, but not a type for "a value of type T or nothing at all". Should we follow Scala's example and add it?
>
>
> Andrei
Yes! Option is super useful. Use it all the time in Scala and Java (via Guava library).
I suppose it will be defined as a range, so map will work on it?
One of the useful things about options are the ability to chain them via flatMap, will this usecase be handled?
|
December 10, 2013 Re: Option!T | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Tuesday, 10 December 2013 at 17:28:26 UTC, Andrei Alexandrescu wrote:
> I talked to a programmer who knows Scala (among others) and he mentioned the usefulness of the Option type - a zero or one element collection (range in D terminology). Here's an article discussing it: http://danielwestheide.com/blog/2012/12/19/the-neophytes-guide-to-scala-part-5-the-option-type.html
I really came to love Option when I was working in F#. One of the things I love about F# is how the language strongly discourages nulls. Even Anders went on video saying that he regretted making reference types nullable in C#.
Of course, there's no way to remove the nullable-by-default nature of reference types in D2, but a guy can dream. =]
|
December 10, 2013 Re: Option!T | ||||
---|---|---|---|---|
| ||||
Posted in reply to JR | On 12/10/13 9:40 AM, JR wrote:
> On Tuesday, 10 December 2013 at 17:28:26 UTC, Andrei Alexandrescu wrote:
>> We have only(x) (http://dlang.org/phobos/std_range.html#.only) to be a
>> collection of exactly one value, but not a type for "a value of type T
>> or nothing at all".
>
> Is this not what Nullable!T is?
Nullable is not a range.
Andrei
|
December 10, 2013 Re: Option!T | ||||
---|---|---|---|---|
| ||||
Posted in reply to Max Klyga | On 12/10/13 9:47 AM, Max Klyga wrote:
> On 2013-12-10 17:28:26 +0000, Andrei Alexandrescu said:
>
>> I talked to a programmer who knows Scala (among others) and he
>> mentioned the usefulness of the Option type - a zero or one element
>> collection (range in D terminology). Here's an article discussing it:
>> http://danielwestheide.com/blog/2012/12/19/the-neophytes-guide-to-scala-part-5-the-option-type.html
>>
>>
>> We have only(x) (http://dlang.org/phobos/std_range.html#.only) to be a
>> collection of exactly one value, but not a type for "a value of type T
>> or nothing at all". Should we follow Scala's example and add it?
>>
>>
>> Andrei
>
> Yes! Option is super useful. Use it all the time in Scala and Java (via
> Guava library).
> I suppose it will be defined as a range, so map will work on it?
> One of the useful things about options are the ability to chain them via
> flatMap, will this usecase be handled?
Yah, looks like flatMap is also useful (independently from Option). Should actually be flatMap!(R, uint depth = uint.max).
Andrei
|
December 10, 2013 Re: Option!T | ||||
---|---|---|---|---|
| ||||
Posted in reply to Yota | Am 10.12.2013 18:54, schrieb Yota: > On Tuesday, 10 December 2013 at 17:28:26 UTC, Andrei Alexandrescu wrote: >> I talked to a programmer who knows Scala (among others) and he >> mentioned the usefulness of the Option type - a zero or one element >> collection (range in D terminology). Here's an article discussing it: >> http://danielwestheide.com/blog/2012/12/19/the-neophytes-guide-to-scala-part-5-the-option-type.html >> > > I really came to love Option when I was working in F#. One of the > things I love about F# is how the language strongly discourages nulls. > Even Anders went on video saying that he regretted making reference > types nullable in C#. > > Of course, there's no way to remove the nullable-by-default nature of > reference types in D2, but a guy can dream. =] It would probably break a lot of code, but the Eiffel, Kottlin's approach could be used. In those languages, unless it is proven that a reference type is valid you cannot make use of its value. Eiffel http://docs.eiffel.com/sites/default/files/void-safe-eiffel.pdf Kotlin http://confluence.jetbrains.com/display/Kotlin/Null-safety -- Paulo |
December 10, 2013 Re: Option!T | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paulo Pinto | On 12/10/13 10:21 AM, Paulo Pinto wrote:
> Am 10.12.2013 18:54, schrieb Yota:
>> On Tuesday, 10 December 2013 at 17:28:26 UTC, Andrei Alexandrescu wrote:
>>> I talked to a programmer who knows Scala (among others) and he
>>> mentioned the usefulness of the Option type - a zero or one element
>>> collection (range in D terminology). Here's an article discussing it:
>>> http://danielwestheide.com/blog/2012/12/19/the-neophytes-guide-to-scala-part-5-the-option-type.html
>>>
>>>
>>
>> I really came to love Option when I was working in F#. One of the
>> things I love about F# is how the language strongly discourages nulls.
>> Even Anders went on video saying that he regretted making reference
>> types nullable in C#.
>>
>> Of course, there's no way to remove the nullable-by-default nature of
>> reference types in D2, but a guy can dream. =]
>
> It would probably break a lot of code, but the Eiffel, Kottlin's
> approach could be used.
>
> In those languages, unless it is proven that a reference type is valid
> you cannot make use of its value.
>
> Eiffel
> http://docs.eiffel.com/sites/default/files/void-safe-eiffel.pdf
>
> Kotlin
> http://confluence.jetbrains.com/display/Kotlin/Null-safety
Not that this is not worth discussing, but this is a different topic. I'm talking about ranges of zero or one elements.
Andrei
|
December 10, 2013 Re: Option!T | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu: >Should we follow Scala's example and add it? Making an Option a D Range means it becomes a Mondad :-) There's then a need for more awareness of Option!T in map/filter/zip. Related: https://d.puremagic.com/issues/show_bug.cgi?id=9086 Bye, bearophile |
December 10, 2013 Re: Option!T | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Am 10.12.2013 19:34, schrieb Andrei Alexandrescu:
> On 12/10/13 10:21 AM, Paulo Pinto wrote:
>> Am 10.12.2013 18:54, schrieb Yota:
>>> On Tuesday, 10 December 2013 at 17:28:26 UTC, Andrei Alexandrescu wrote:
>>>> I talked to a programmer who knows Scala (among others) and he
>>>> mentioned the usefulness of the Option type - a zero or one element
>>>> collection (range in D terminology). Here's an article discussing it:
>>>> http://danielwestheide.com/blog/2012/12/19/the-neophytes-guide-to-scala-part-5-the-option-type.html
>>>>
>>>>
>>>>
>>>
>>> I really came to love Option when I was working in F#. One of the
>>> things I love about F# is how the language strongly discourages nulls.
>>> Even Anders went on video saying that he regretted making reference
>>> types nullable in C#.
>>>
>>> Of course, there's no way to remove the nullable-by-default nature of
>>> reference types in D2, but a guy can dream. =]
>>
>> It would probably break a lot of code, but the Eiffel, Kottlin's
>> approach could be used.
>>
>> In those languages, unless it is proven that a reference type is valid
>> you cannot make use of its value.
>>
>> Eiffel
>> http://docs.eiffel.com/sites/default/files/void-safe-eiffel.pdf
>>
>> Kotlin
>> http://confluence.jetbrains.com/display/Kotlin/Null-safety
>
> Not that this is not worth discussing, but this is a different topic.
> I'm talking about ranges of zero or one elements.
>
> Andrei
>
>
Ah ok
|
Copyright © 1999-2021 by the D Language Foundation