std.sumtype?
Steven Schveighoffer
schveiguy at gmail.com
Tue Mar 30 17:01:29 UTC 2021
On 3/30/21 12:32 PM, Paul Backus wrote:
>> Separate thing - I think the catch-all handler could be a bit better
>> documented. Is the lack of a type that triggers it? Or is underscore
>> ('_') special (ala Scala). If the latter, then are the '_1' and '_2'
>> forms shown in the multiple dispatch examples special? (I'm guessing
>> that there's nothing special about the underscore forms, but people
>> familiar with Scala might assume some else.) I'm looking at the docs
>> here: https://pbackus.github.io/sumtype/sumtype.SumType.html.
>
> Your guess that the underscore is not special is correct. This should be
> clear from reading the documentation for match [1], but I expect there
> are many users who read only the examples and skip the prose, so it
> would be best to add a note about this to the examples as well.
>
What might be nice is to have some simplifiers for match to prevent
having to jump through the hoops.
For example, a match flavor that throws by default, or one that ignores
unhandled types. This way, you don't have to write stuff like `(_) {}`
at the end of your handlers.
FWIW, taggedalgebraic has `visit` to enforce all items are handled, and
`tryVisit` that throws if at runtime it determines no visitors match the
current type.
-Steve
More information about the Digitalmars-d
mailing list