draft proposal for Sum Types for D

ryuukk_ ryuukk.dev at gmail.com
Tue Nov 29 18:52:58 UTC 2022


On Tuesday, 29 November 2022 at 13:21:25 UTC, rikki cattermole 
wrote:
>
> "sumtype Option(T) = None | Some(T);"
>
> Supporting ML-ish style syntax is a must. It gives us one 
> liners and it helps with on boarding those with familiarity 
> with the source material. My bet is a lot of people will prefer 
> it when they are not worried about documenting each member.
>

I disagree, that syntax with `|` is inconsistent with every other 
constructs, no need to create mental gymnastic

```D
sumtype T {
}
```

works like

```D
struct T {
}
```

works like

```D
enum T {
}
```

works like

```D
class T {
}
```

works like

```D
interface T {
}
```

consistency is key



> Consider:
> 
> ```d
> SumType!(int, long, float, double) first() {
> 	return second();
> }
> 
> SumType!(int, float) second() {
> 	return typeof(return).init;
> }
> ```


Why consider? to me this looks like a mistake to allow this



About the ? query thing, why not at the end?


I'm pretty excited to finally see a proper DIP for tagged union, 
this feature will greatly improve my code base, specially with 
the way to currently designed my event system!





More information about the Digitalmars-d mailing list