Dispatching on a variant
#ponce
aliloko at gmail.com
Sat Sep 26 15:51:19 PDT 2009
> Exactly, this is what I mentioned previously. Isn't it ugly compared to
>
> type Event = Mouse | Key | Move;
>
> void dispatchEvent(Event event) {
> match(event) {
> Mouse m => m.squeek();
> Key k => ...
> ...
> }
> }
>
> What's with all the language proposals here? Why hasn't anyone proposed
> this before? This is in fact very helpful - that's why several modern
> languages have adopted it.
Algebraic data types are indeed a neat feature.
But the languages which implemented this (ML, Haskell, scala...) seems only to be functionals one.
I suppose it's because it replaces enums and unions for those. In procedural languages one can emulate this with 1 enum + 1 union.
I would prefer having some computed goto (through final switch).
More information about the Digitalmars-d
mailing list