Structural exhaustive matching

2015-04-21 Thread Jadbox via Digitalmars-d-learn
What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do ADTs in D.

Re: Structural exhaustive matching

2015-04-21 Thread bearophile via Digitalmars-d-learn
Jadbox: I'm curious on what the best way to do ADTs in D. Sometimes there's no best way, there are several alternative ways with different tradeoffs. D isn't a functional language and there's no really good way to do ADTs in D. You can use plus a "final switch". Or you can use Algebraic fro

Re: Structural exhaustive matching

2015-04-21 Thread Justin Whear via Digitalmars-d-learn
On Tue, 21 Apr 2015 15:36:27 +, Jadbox wrote: > What's the best equivalent to Rust's structural enum/pattern (match)ing? > Is it also possible to enforce exhaustive matches? > Basically, I'm curious on what the best way to do ADTs in D. std.variant.Algebraic implements ADTs: import std.varia

Re: Structural exhaustive matching

2015-04-21 Thread weaselcat via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 15:36:28 UTC, Jadbox wrote: What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do ADTs in D. D's ADTs are in std.variant, the equivalent of match

Re: Structural exhaustive matching

2015-04-21 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-04-21 17:36, Jadbox wrote: What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do ADTs in D. There's something call "castSwitch" [1], perhaps not what you're looking f

Re: Structural exhaustive matching

2015-04-21 Thread Martin Nowak via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 15:36:28 UTC, Jadbox wrote: What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do ADTs in D. If it needs to be really fast, use final switch on t

Re: Structural exhaustive matching

2015-04-21 Thread weaselcat via Digitalmars-d-learn
On Wednesday, 22 April 2015 at 04:54:39 UTC, Martin Nowak wrote: On Tuesday, 21 April 2015 at 15:36:28 UTC, Jadbox wrote: What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do