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: a07f3367d7,dbbbb21ed7f581b X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!u16g2000pru.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Operation can be dispatching in only one type Date: Mon, 16 Nov 2009 13:35:00 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <025105f2-5571-400e-a66f-ef1c3dc9ef32@g27g2000yqn.googlegroups.com> <94e76749-c49c-45aa-b7dc-386da0d71c66@e4g2000prn.googlegroups.com> <1u0im1tdws15u.1n9v9rz7bu4t4$.dlg@40tude.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1258407300 724 127.0.0.1 (16 Nov 2009 21:35:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 16 Nov 2009 21:35:00 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: u16g2000pru.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:8118 Date: 2009-11-16T13:35:00-08:00 List-Id: On Nov 16, 12:28=A0pm, "Dmitry A. Kazakov" wrote: > On Mon, 16 Nov 2009 09:43:06 -0800 (PST), Adam Beneschan wrote: > > By the way, for a while I was considering requesting a language change > > to allow this sort of restricted multiple dispatch, in cases where a > > primitive operation of two types could be declared and inherited for > > two derived types that are derived in the same package, and when > > dispatching, the program would check to make sure the two actual types > > really were declared in the same package. =A0This would avoid having to > > deal with M x N combinations of types---something that I think is an > > issue with MI---since it only deals with pairs (or triplets, etc.) of > > types that are defined to "go together". > > But you still have these combinations independently on where you derive. > You allow the "diagonal" of the full dispatching table. I.e. the > combinations: > > A1, B1, > A2, B2, > A3, B3 > > But other combinations are still there, because they can be spelt. It is > just so that they raise Constraint_Error. This "diagonal" behavior is wha= t > we already have for multi-methods (a form of MD with only one hierarchy > A=3DB). I suppose this is one of the motivations of your proposal. > > But the problem with "diagonal" dispatch is that it is inconsistent with > the idea of static typing. I would insist on the design rule that dispatc= h > shall never fail in a legal program. I.e. the compiler shall enforce all > possible combinations of types no later than at compile time. Since a call to a dispatching operation may have parameters that are themselves of class-wide types, I don't think this is possible. In Ada as it exists currently, you can declare a primitive operation with two parameters of the same tagged type (maybe that's what you meant by "multi-method"---sorry, I don't know the jargon). E.g. type T is abstract tagged null record; procedure Some_Operation (Param_1 : T; Param_2 : T); If you later call Some_Operation (X, Y); and X is declared to be of type T1 (a descendant of T) and Y is declared to be of type T2 (also a descendant of T), then the compiler can statically determine that this will fail. But if either X or Y (or both) is declared to be of type T'Class, then the compiler can't statically tell whether the dispatch will fail or not. So a runtime check is needed. Similarly for the proposal I was thinking of making. > Further, it > shall not "invent" broken implementations. In "diagonal" dispatch it woul= d > do (and does) exactly this, it would override A1, B2 with an implementati= on > raising Constraint_Error. > > At the same time the case represented by "diagonal" dispatch is very > important in other situations, like parallel hierarchies of types. E.g. > when we wanted to force a new instance from B'Class for each new instance > from A'Class. But again that enforcement shall be static. BTW, it is not > multiple dispatch. Technically this is rather single dispatch where the > tuple of types (A, B) is considered as root of some class of tuples, in > which (A1, B1), (A2, B2) are instances. Presently we have nothing in the > language to handle this (except the jack-of-all-trades, generics). It wou= ld > be interesting to speculate how tuples can be supported in Ada, especiall= y > their flattening in the arguments lists, and using tuples as multiple > results of a function. > > > I could try to write a > > proposal if there's enough interest, but I think it's too late to get > > into the next language revision. > > I am incredibly interested in MD (and in tuples as well), but I think we > should not touch it until we knew how to do it right. I don't think the proposal I was considering was a solution to MD, but rather to a smallish subset of MD-related problems---although it was a subset I thought would be useful, and I may have run into a case in my own code where I would have wanted to use it. -- Adam