On 26-Oct-2015 12:16, Jacob Carlborg wrote:
On 2015-10-25 19:23, Dmitry Olshansky wrote:
I humbly believe that D may just add special re-write rule to the switch
statement in order to allow user-defined switchable types. This goes
along nicely with the trend - e.g. foreach statement works with anything
having static range interfaces or opApply.
Do you think that could handle all different type of patterns? For
example extractor patterns:
match x {
case Foo(bar) => println(bar)
}
The above is Scala.
Scala does it with a bit of re-writes and partially hard-wired logic
(mostly to optimize). I don't see a problem with it and D would be
better off with something similar.
Current switch is both too lax (accepts variables) and too rigid (only
integers, string and soon(?) pointers).
--
Dmitry Olshansky