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=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable 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!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Marius Amado Alves Newsgroups: comp.lang.ada Subject: Re: Formal and informal type systems? Date: Wed, 29 Sep 2004 10:10:23 +0100 Organization: Cuivre, Argent, Or Message-ID: References: <49dc98cf.0408110556.18ae7df@posting.google.com> NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1096449047 18470 212.85.156.195 (29 Sep 2004 09:10:47 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Wed, 29 Sep 2004 09:10:47 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en In-Reply-To: X-OriginalArrivalTime: 29 Sep 2004 09:10:26.0654 (UTC) FILETIME=[28B977E0:01C4A604] X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:4365 Date: 2004-09-29T10:10:23+01:00 > 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)? An application of Patterns to types would only work in Reflexive_Ada. > (* 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. :-) See, Ada can do it :-) But I have no beef conceding that ML is better at this than Ada. Your code would translate to an Ada class of tagged types rooted at Foo and classwide types to simulate types values. I'll let the realisation of this as an exercise to the OOP folks :-) (Is there a comp.lang.comparate group?)