Return-Path: X-Original-To: apmail-incubator-flex-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-flex-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3CF63B0F3 for ; Mon, 16 Jan 2012 17:46:32 +0000 (UTC) Received: (qmail 85077 invoked by uid 500); 16 Jan 2012 17:46:32 -0000 Delivered-To: apmail-incubator-flex-dev-archive@incubator.apache.org Received: (qmail 85027 invoked by uid 500); 16 Jan 2012 17:46:31 -0000 Mailing-List: contact flex-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: flex-dev@incubator.apache.org Delivered-To: mailing list flex-dev@incubator.apache.org Received: (qmail 85019 invoked by uid 99); 16 Jan 2012 17:46:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Jan 2012 17:46:31 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of webdoublefx@hotmail.com designates 65.55.111.77 as permitted sender) Received: from [65.55.111.77] (HELO blu0-omc2-s2.blu0.hotmail.com) (65.55.111.77) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Jan 2012 17:46:24 +0000 Received: from BLU162-W30 ([65.55.111.72]) by blu0-omc2-s2.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 16 Jan 2012 09:46:02 -0800 Message-ID: Content-Type: multipart/alternative; boundary="_6551823e-2725-4ab4-9ff7-158878b8b792_" X-Originating-IP: [82.247.153.175] From: Web DoubleFx To: Subject: RE: Method overloading work-around: the problems & possible solution Date: Mon, 16 Jan 2012 18:46:02 +0100 Importance: Normal In-Reply-To: <008401ccd474$7f514870$7df3d950$@davidarno.org> References: <008401ccd474$7f514870$7df3d950$@davidarno.org> MIME-Version: 1.0 X-OriginalArrivalTime: 16 Jan 2012 17:46:02.0941 (UTC) FILETIME=[B70FFED0:01CCD476] --_6551823e-2725-4ab4-9ff7-158878b8b792_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable ---------------------------------------- > From: david@davidarno.org > To: flex-dev@incubator.apache.org > Subject: Method overloading work-around: the problems & possible solution > Date: Mon=2C 16 Jan 2012 17:30:09 +0000 > > Consider the following code example: > > interface IA > { > function foo(s:String):void=3B > } > > interface IB > { > function foo(i:int):void=3B > } > > class AB implements IA=2C IB > { > public function foo(s:String):void {} > public function foo(i:int):void {} > public function foo(u:uint):void {} > public function foo(n:Number):void {} > public function foo(o:Object):void {} > } > > Now imagine we have a modified version of the compiler that supports meth= od > overloading. AB compiles to: > class AB -> > foo_String_void -> String -> void -> {} > foo_int_void -> int -> void -> {} > foo_uint_void -> uint -> void -> {} > foo_Number_void -> Number -> void -> {} > foo_Object_void -> Object -> void -> {} > > > There are problems with this. First the compile time problems: > > class TestAB > { > public function testFoo():void > { > var ab:AB =3D new AB()=3B > ab.foo(1)=3B // <- which foo does this call? int=2C uint or Number? > ab.foo(null)=3B // <- and this one? String or Object? > ab["foo"]("")=3B // <- how do we map this to ab.foo_String_void() ? > } > } > > Then there are runtime problems: > > class TestIA > { > public function testFoo():void > { > var ab:AB =3D new AB()=3B > callFoo(ab=2C "")=3B > > var name:String =3D "foo"=3B > ab[name]("")=3B // <- how do we map this to > ab.foo_String_void() ? > } > > private function callFoo(reference:IA=2C value:String):void > { > reference.foo(value)=3B // <- how do we map foo to foo_String_void? > } > } > > I think the first problem (which method to use when the data is ambiguous= ) > can be solved by a set of simple rules. I think the other problems could = be > solved if we modify what AB gets compiled to: > > class AB -> > foo_String_void -> String -> void -> {} > foo_int_void -> int -> void -> {} > foo_uint_void -> uint -> void -> {} > foo_Number_void -> Number -> void -> {} > foo_Object_void -> Object -> void -> {} > foo -> Object -> void -> > { > if (p1 is String) > { > call foo_String_void=2C p1 > } > ... > } > > We put in place a catch-all foo that handles all the situations where the > compiler cannot work out the mapping at compile time. > > Thoughts? > > David. > Maybe there's a way=2C one year ago=2C Avik Chaudhuri who works in the Lang= uages and Runtimes Group at Adobe=92s Advanced Technology Labs wrote in an = article [1] he was working Gradual Type Inference for ActionScript=2C one y= ear after=2C I don't know at which point is its work but that might be a wa= y to achieve this result. Fr=E9d=E9ric Thomas [1] http://blogs.adobe.com/avikchaudhuri/2011/01/19/setting-the-context/ = = --_6551823e-2725-4ab4-9ff7-158878b8b792_--