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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c406e0c4a6eb74ed X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!news.cs.univ-paris8.fr!informatik.uni-bremen.de!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: Formal and informal type systems? Date: Wed, 29 Sep 2004 00:56:27 +0000 (UTC) Organization: GMUGHDU Message-ID: References: <49dc98cf.0408110556.18ae7df@posting.google.com> NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1096419387 28722 134.91.1.34 (29 Sep 2004 00:56:27 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Wed, 29 Sep 2004 00:56:27 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: g2news1.google.com comp.lang.ada:4349 Date: 2004-09-29T00:56:27+00:00 List-Id: Marius Amado Alves wrote: : : Maybe. I was kind of teasing. I suggested GNAT.Spitbol but I may as well : suggest my package Patterns (wait for the secret URL) which support : pattern matching of strings of any type of component. And this structure : subsumes tuples, no? : Now, my understanding of what you guys are saying equates to a : (non-existing) way in Ada to reflect on record structure, be it by : conversion to array or other device. There is more to ML types, and reflection is not in sight. Will your Patterns handle argument pattern matching like in the following ML example (which omits curried functions, but uses functions as values and in patterns)? (* a polymorphic recursive type *) datatype Foo = Pea (* a single item *) | Coord of int * int (* a point *) | Finder of Foo -> string (* some function *) | Spider of Foo list; (* a Foo is a Foo is a ... *) fun explnum (Pea) = [(0, "a pea")] | explnum (Coord(x, y)) = [(x * y, "product")] | explnum (Finder(f)) = [(String.size (f (Finder f)), "apply")] | explnum (Spider []) = [(0, "done")] | explnum (Spider(w :: ws)) = hd (explnum w) :: explnum (Spider ws); fun print (Pea) = "P" | print (Coord(_, _)) = "C" | print (Finder(_)) = "F" | print (Spider []) = "" | print (Spider(w :: ws)) = "(" ^ (print w) ^ print (Spider ws) ^ ")"; val sample = Spider([ Pea, Spider([Coord(47, 11)]), Finder(print) ]) When I now write - print sample; I get val it = "(P((C)(F)))" : string Typing - explnum sample; gives val it = [(0,"a pea"),(517,"product"),(1,"apply"),(0,"done")] : (int * string) list Now, see what is already there... -ListPair.unzip; val it = fn : ('a * 'b) list -> 'a list * 'b list For me, the nice thing here is that the "dispatching" subprogram definitions for the "Foo'class types" are always next to each other. They must be exhaustive or else you will be warned, I find this similar to Ada's case statements. Last but not least, using argument patterns resembles definition by cases :-) (The list (tree, ...) functions and functionals are valuable in functional programming. Similar mechanisms are available with STL algorithms. Ada.Containers offers a way to make a similar set of useful subprograms. Only, the Ada.Containers way. :-) -- Georg