From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,24d7acf9b853aac8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!feeder3.cambriumusenet.nl!feeder2.cambriumusenet.nl!feed.tweaknews.nl!212.27.60.9.MISMATCH!feeder2-2.proxad.net!proxad.net!feeder1-2.proxad.net!cleanfeed3-b.proxad.net!nnrp14-1.free.fr!not-for-mail Date: Thu, 12 Aug 2010 14:43:28 +0200 From: _FrnchFrgg_ User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100619 Icedove/3.0.5 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Structural unification (pattern matching) in Ada [was: Re: S-expression I/O in Ada] References: <547afa6b-731e-475f-a7f2-eaefefb25861@k8g2000prh.googlegroups.com> <1omt2srxtpsga$.c3hbxthzo6cf.dlg@40tude.net> <1e4cch2df5uyb.18brqdd16dhv8.dlg@40tude.net> <14y70ke8am9qw$.2csc9eflvigg.dlg@40tude.net> <4c601b5c$0$7665$9b4e6d93@newsspool1.arcor-online.net> <9czktq4ntzq7.fhbsnocx0x4w$.dlg@40tude.net> <4c6078f9$0$12500$426a74cc@news.free.fr> <4c6132d2$0$8378$426a74cc@news.free.fr> <4c61dafd$0$14549$426a74cc@news.free.fr> <4oebq9a8m8et$.gvv6eyo3umfh$.dlg@40tude.net> <4c62e31a$0$10493$426a34cc@news.free.fr> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <4c63ec70$0$8377$426a74cc@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 12 Aug 2010 14:43:29 MEST NNTP-Posting-Host: 82.233.38.63 X-Trace: 1281617009 news-1.free.fr 8377 82.233.38.63:47963 X-Complaints-To: abuse@proxad.net Xref: g2news1.google.com comp.lang.ada:13172 Date: 2010-08-12T14:43:29+02:00 List-Id: Le 11/08/2010 21:43, Robert A Duff a �crit : > 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 checks for full coverage, and warns about it (I even think you can make it an error), so nothing would prevent such a feature in Ada to make lack of full coverage an error. Overlapping I don't really know, but if the check is feasible, then of course I'd expect it to be in Ada. > 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). Why not ? The only way I use overlapping is when I want a special case of a bigger rule treated separately (like in: do something special when the root of the AST is an addition, and one of the leaves is an integer, then use the generic "operator handling" for every other mathematical operator). I never ever wrote cases where a rule overlaped an other without one being a subset of the other. And subset-overlapping can be rewritten to not overlap by matching for the full case and using a nested "case" statement. So overlaping is not really needed. > Note that "when others" in Ada turns off the full coverage rule. > Similar to "_" in OCaml -- it means "none of the above". Just as a side note, "_" in OCaml is just like any other variable (you can even write "let _ = 5 in" or "let (_,x) = function_returning_a_couple arg1 arg2 in"; its value is just never stored (and it is illegal to use it as a r-value) >> 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. ;-) I meant with a decent integration with the normal 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. ;-) My bad. Sorry for that. Julien