std.sumtype?
SealabJaster
sealabjaster at gmail.com
Sun Aug 29 19:19:54 UTC 2021
On Sunday, 29 August 2021 at 15:05:57 UTC, Paul Backus wrote:
> ...
It is also of course totally possible I'm not using sumtypes
right, but I'm frequently in situations such as this:
```
private string expectSingleIdentifier(Token tok, Expression[] exp)
{
string ret;
exp[0].match!(
(IdentifierExpression exp) { ret = exp.ident; },
(_) { throw new Exception(...); }
);
return ret;
}
```
While in this case I still have to go through `match` in order to
access the value, sometimes I simply want to do a type check, and
going through `match` seems a bit overkill.
I guess it's just a niche case (wanting to 'abort' on a bad value
rather than keep going) I keep running into, likely a sign I need
to change my mindset rather than anything else.
Or I'm just using it as a wrong abstraction >;3
In this specific case as well I don't believe I can use `return
match!(...)` because I can't return anything in the "bad" case,
since I'd then get an unreachable code error. Very minor yet
annoying thing, but that's more a language issue rather than
something inherent to SumType.
And I keep forgetting to make the difference between a tagged
union and a sum type, which is likely muddying my opinion since
it's easy to extract and test values with the former case.
More information about the Digitalmars-d
mailing list