digitalmars.D - Re: Dispatching on a variant
- #ponce <aliloko gmail.com> Sep 26 2009
- language_fan <foo bar.com.invalid> Sep 26 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).
Sep 26 2009
Sat, 26 Sep 2009 18:51:19 -0400, #ponce thusly wrote: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).
Agreed. On the other hand I cannot fully agree that Scala is more a functional language than something else. The core is both object oriented and functional. It is even more object oriented (purer) than most mainstream C-like languages. By this I mean that in my opinion it is not impossible to imagine that D also implemented something like case classes and extended switch to handle also simple patterns.
Sep 26 2009