Second draft: Sum Type by Struct

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Tue Sep 15 15:56:03 UTC 2026


On 07/09/2026 4:58 AM, MaxB wrote:
> __sumtype Form = int phone | int work;  // OK: both are int, 
> distinguished by name
> 
> -----
> 
> How to do the match?
> 
> Does this work?
> 
> f.match {
>    (phone) => doSomethingWith(phone),
>    (work) => doSomethingOtherWith(work)
> }

That should.

> How do I use a different name instead the tagname? Something like:
> 
> f.match {
>    (phone(p)) => doSomethingWith(p),
>    (work(w)) => doSomethingOtherWith(w)
> }

There is no way to do that.

We do have ref variables, and you can declare them with comma expression 
I'm pretty sure that this could work:

```d
(work) => ref num = work, doSomething(num)
```



More information about the dip.development mailing list