SumType in Phobos?
Paul Backus
snarwin at gmail.com
Wed Feb 19 17:33:11 UTC 2020
On Wednesday, 19 February 2020 at 08:23:57 UTC, Petar Kirov
[ZombineDev] wrote:
> On Wednesday, 19 February 2020 at 06:52:04 UTC, Ernesto
> Castellotti wrote:
>> How about including SumType
>> (https://github.com/pbackus/sumtype) in Phobos?
>>
>> We know that std.variant.Algebraic has problems (nogc, nothrow
>> etc), SumType would be a wonderful solution to provide a
>> tagged union in the std.
>>
>> In my opinion it could be put without too many changes in
>> std.experimental.sumtype, it already has unittest and good
>> documentation.
>>
>> I think it's a good starting point to start modernizing phobos
>> to make it even more functional and suitable for everything.
>
> I use SumType in my projects and it is great! However the last
> thing I wish for is for it to be part of the standard library
> (at least in the current status quo) as this will limit bug fix
> releases to once per month and feature releases once every two
> months.
>
> I sympathize with the intention of "standardizing" on
> high-quality API, replacing existing suboptimal designs, etc.,
> however the current release model of Phobos is bad and
> shouldn't be replicated. Tying the release of libraries to the
> release of the compiler+runtime makes no sense to me.
This is a good point, and I agree that it's important to
acknowledge the downsides of having something in Phobos rather
than on code.dlang.org. However, in the case of SumType, I think
there's a convincing argument to be made that it, or something
like it, ought to be in the standard library.
In the C++ community, certain types are regarded as "vocabulary
types"--types that "provide a single lingua franca, a common
language, for dealing with [their] domain." [1] The prototypical
example is std::string. What's important about these types is not
just that they're available, but that they're standardized.
std::string isn't just one possible choice of string class, it's
the *obvious* choice.
Which types benefit the most from this kind of standardization?
In broad terms, types that are used for communication between
different libraries or modules. These tend to be general-purpose,
domain-agnostic types like strings, dynamic arrays, associative
arrays, tuples, and--that's right--sum types.
I don't particularly care if SumType or some other implementation
is accepted into Phobos (though of course, I prefer SumType
myself), but I think it's important for there to be a sum type in
D that (1) meets the quality standards of today's D programmers,
and (2) is the obvious choice. Currently, SumType satisfies #1,
but not #2; and Algebraic satisfies #2, but not #1.
Personally, I don't think it's possible to make a dub package
"more obvious" than a standard library module, no matter how many
shiny stickers you put on it. So, given that Algebraic is already
in Phobos, and likely to remain there for a long time, I think
the most sensible path forward is for SumType, or something like
it, to be added alongside it.
[1]
https://www.oreilly.com/library/view/mastering-the-c17/9781787126824/c6737dd3-47fa-4719-a459-72afac90857c.xhtml
More information about the Digitalmars-d
mailing list