Pattern matching: Callback For Matching Type
Harry Gillanders
contact at harrygillanders.com
Wed May 29 19:38:45 UTC 2024
On Wednesday, 29 May 2024 at 18:24:19 UTC, Richard (Rikki) Andrew
Cattermole wrote:
> Today I woke up and found I wanted to write up a proposal for
> pattern matching for D.
>
> Permanent:
> https://gist.github.com/rikkimax/79cbe199618b3f99104f7df2fc2a9681/e0e6dd44f7477be962e6c71312ba08a1fe1ee8d6
> Latest:
> https://gist.github.com/rikkimax/79cbe199618b3f99104f7df2fc2a9681
> A __tag member must evaluate to an integer
Does this mean `__tag` can also be a member-function? For types
where the tag doesn't need any storage (like NaN-boxing, disjoint
enums, etc.).
I think it would be nice if the match-patterns were semicolon
delimited, so that `static if` and `static foreach` and whatnot
could be used in a `match` block—something like:
```d
mtu1.match {
static if (condition) {
(float v) => writeln("a float! ", v);
}
static foreach (T; Types) {
(T v) => writeln(T.stringof, " ", v);
}
v => writeln("catch all! ", v);
}
```
More information about the dip.ideas
mailing list