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=0.7 required=5.0 tests=BAYES_00,MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,75a8a3664688f227 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-02-01 23:20:08 PST Path: supernews.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp2.deja.com!nnrp1.deja.com!not-for-mail From: mark_lundquist@my-deja.com Newsgroups: comp.lang.ada Subject: Multiple dispatch (was Re: Parameter Modes, In In Out and Out Date: Fri, 02 Feb 2001 07:06:05 GMT Organization: Deja.com Message-ID: <95dm8r$a9a$1@nnrp1.deja.com> References: <7Cx56.90736$A06.3322588@news1.frmt1.sfba.home.com> <937jab$s23$1@nnrp1.deja.com> <3A57CD7F.2228BFD5@brighton.ac.uk> <938p3u$omv$1@nnrp1.deja.com> <93cagm$c1j$1@nnrp1.deja.com> <93e4e6$ucg$1@nnrp1.deja.com> <93encq$brm$1@nnrp1.deja.com> <93f6ar$m44$1@nnrp1.deja.com> <93flab$2mh$1@nnrp1.deja.com> <93fqau$6m2$1@nnrp1.deja.com> <93h9mo$bbm$1@nnrp1.deja.com> <93il87$iqo$1@nnrp1.deja.com> <93k6dv$qt6$1@nnrp1.deja.com> <93ko49$auq$1@nnrp1.deja.com> <93modu$36k$1@nnrp1.deja.com> <93n2co$alq$1@nnrp1.deja.com> <93q39q$oq0$1@nnrp1.deja.com> <93q6cd$r3k$1@nnrp1.deja.com> <93v898$k80$1@nnrp1.deja.com> NNTP-Posting-Host: 24.20.66.55 X-Article-Creation-Date: Fri Feb 02 07:06:05 2001 GMT X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt) X-Http-Proxy: 1.1 x56.deja.com:80 (Squid/1.1.22) for client 24.20.66.55 X-MyDeja-Info: XMYDJUIDmark_lundquist Xref: supernews.google.com comp.lang.ada:4846 Date: 2001-02-02T07:06:05+00:00 List-Id: The trail has kind of gone cold on this, but oh well.. (Why do you think they call it "Deja"? :-) In article <93v898$k80$1@nnrp1.deja.com>, dmitry6243@my-deja.com wrote: > In article <93q6cd$r3k$1@nnrp1.deja.com>, > Robert Dewar wrote: > > > > Now if your emphasis is on *complete* here, i.e. with all the > > details of semantic interactions worked out, then that > > statement makes sense, but we don't need to go there to > > discuss whether MD is useful. Just sketch out what MD would > > mean to you in an Ada environment, and produce an example, > > showing what you would like to be able to write. [Dmitri's example:] > -- > -- The base type uses some set of distribution functions > -- of the confidence factor. The set is closed for +,-,*,/. > -- The implementation could be potentially very slow. > -- > package FuzzyNumbers is > type FuzzyNumber is tagged private; > function "+" (Left, Right : FuzzyNumber) > return FuzzyNumber; > ... > end FuzzyNumbers; > -- > -- A derived type that uses some specialized subset of > -- the distribution functions. It is closed for only > -- +,- but extremely fast. We derive it because we want to > -- mix operands of both types and make some class-wide > -- programming too. > -- > package FuzzyNumbers.Special is > type SpecialFuzzyNumber is new FuzzyNumber with > null record; > function "+" (Left, Right : SpecialFuzzyNumber) > return SpecialFuzzyNumber; > ... > end FuzzyNumbers.Special; > -- > -- So far it is Ada 95. Let we make a fuzzy neuro network > -- to fake our innoncent customers (:-)). We implement > -- nodes of the network. Each node has a procedure > -- calculating the output: > -- > with FuzzyNumbers; use FuzzyNumbers; > package Network is > type Node is tagged private; > type Link is access Node; > function Compute > ( X : Node; > Input1 : FuzzyNumber'Class; > Input2 : FuzzyNumber'Class > ) return FuzzyNumber'Class; > ... > end Network; > -- > -- Summator is an instance of a node: > -- > package Network.Summators is > type Summator is new Node with null record; > function Compute > ( X : Summator; > Input1 : FuzzyNumber'Class; > Input2 : FuzzyNumber'Class > ) return FuzzyNumber'Class; > ... > end Network.Summators; > -- > -- Now a naive implementation of the summator > -- node: > -- > package body Network.Summators is > function Compute > ( X : Summator; > Input1 : FuzzyNumber'Class; > Input2 : FuzzyNumber'Class > ) return FuzzyNumber'Class is > begin > return Input1 + Input2; -- Opps! > end Compute; > end Network.Summators; > -- > -- This implementation will time to time entertain us with > -- Constraint_Error. The problem is that the developer > -- expected here a triple dispatch to + involving the result, > -- the left and the right operands. If they expected triple dispatch, then they don't know Ada :-) Maybe they really expected covariance, in which case they should have used a generic instead. Another possibility is that the inputs to Compute should be of type FuzzyNumber, not FuzzyNumber'Class. Users of Compute would upcast as necessary. (However, they somehow have to have some reason to believe that upcasting yields a meaningful result, which is hard to know without seeing into the implementations of the abstractions. This is a general difficulty with programming by extension). > The specification > -- of FuzzyNumbers.Special leaves most of the combinations > -- FuzzyNumber, SpecialFuzzyNumbers undefined (Ada 95 does > -- not have MD). An MD aware compiler could say for > -- the specification of FuzzyNumber.Special: > > "Error! All signatures have to be overriden", I.e. not only > > function "+" (Left, Right : SpecialFuzzyNumber) > return SpecialFuzzyNumber; > > but also: > > function "+" (Left : FuzzyNumber; Right : SpecialFuzzyNumber) > return FuzzyNumber; > function "+" (Left : SpecialFuzzyNumber; Right: FuzzyNumber) > return FuzzyNumber; > function "+" (Left, Right : FuzzyNumber) > return FuzzySpecialNumber; > function "+" (Left : FuzzyNumber; Right : SpecialFuzzyNumber) > return SpecialFuzzyNumber; > function "+" (Left : SpecialFuzzyNumber; Right: FuzzyNumber) > return SpecialFuzzyNumber; > function "+" (Left, Right : SpecialFuzzyNumber) > return FuzzyNumber; > > This would fill all the slots of the 3D dispatch table. Some > syntax should be provided to inherit a combination from the > ancestors. I'm not a computer scientist, and I haven't ever studied multiple dispatch, so maybe this is a naive question... but don't you now have a problem with cross-coupled sibling dependencies? Suppose I create another type Wild_And_Wooly_Number, derived also from FuzzyNumber? How do you fill in your table then? Mark Lundquist Sent via Deja.com http://www.deja.com/