Prev: Structural unification (pattern matching) in Ada [was: Re: S-expressionI/O in Ada]
Next: Ada Smileys in C++ lib Conversion
From: Dmitry A. Kazakov on 11 Aug 2010 14:06 On Wed, 11 Aug 2010 19:51:23 +0200, _FrnchFrgg_ wrote: > I don't understand what Streams have to do with ML pattern matching. You mentioned to constructors stream I/O deploys them. > Just to be sure we are talking about the same thing, I read one of you > wishing Ada had a more powerful/generic "switch" construct, and I > noticed that the description of such a "switch" looked like a subset of > structural unification as you can find in most functionnal languages. Can you explain why it looked so to you. Actually I didn't wish a more generic "switch", I wished it as it is. What I needed is an enumeration interface for non-discrete types in order to be able to use them in case. String was just one example. > Perhaps the current Ada is powerful enough to write some function/code > doing this switch machinery, but I was thinking it would be a new > language construct (or an extension of "switch"). That was my first thought, so I asked if you meant *normal* patterns, like regular expressions etc. No, I certainly don't want them in Ada case-statement. Alternatives of a case statement can be evaluated in any order, they can be statically verified for being exhaustive and not overlapping. These are most important features, which any more or less usable pattern language lacks. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: Robert A Duff on 11 Aug 2010 15:43
_FrnchFrgg_ <frnchfrgg(a)free.fr> writes: >...Just to be sure we are talking about the same thing, I read > one of you wishing Ada had a more powerful/generic "switch" construct, > and I noticed that the description of such a "switch" looked like a > subset of structural unification as you can find in most functionnal > languages. Yes, generalizing Ada case statements pushes them roughly in the direction of OCaml pattern matching, which is much more powerful. But one of my favorite features of Ada is that case statements are checked at compile time to make sure they cover all possible cases ("full coverage") and don't overlap. If I remember OCaml correctly, it doesn't do either. OCaml compilers typically warn about full coverage violations, but the language doesn't require full coverage. And overlapping is not warned about, and is commonly used (the alternatives are checked in order, and the first one wins, like an Ada if/elsif/elsif.../else chain). My problem with OCaml is that to understand a pattern, you have to understand all the preceding ones simultaneously, and negate them in your head. I don't think it's easy to get the best of both worlds (powerful pattern matching with full coverage and overlap rules). Note that "when others" in Ada turns off the full coverage rule. Similar to "_" in OCaml -- it means "none of the above". > Perhaps the current Ada is powerful enough to write some function/code > doing this switch machinery, ... Well, one could write an OCaml compiler or interpreter in Ada. ;-) >...but I was thinking it would be a new > language construct (or an extension of "switch"). "case", please. This isn't comp.lang.c. ;-) - Bob |