comp.lang.ada
 help / color / mirror / Atom feed
From: mark_lundquist@my-deja.com
Subject: Multiple dispatch (was Re: Parameter Modes, In In Out and Out
Date: Fri, 02 Feb 2001 07:06:05 GMT
Date: 2001-02-02T07:06:05+00:00	[thread overview]
Message-ID: <95dm8r$a9a$1@nnrp1.deja.com> (raw)
In-Reply-To: 93v898$k80$1@nnrp1.deja.com



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 <robert_dewar@my-deja.com> 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/



  reply	other threads:[~2001-02-02  7:06 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-01-06  0:11 Parameter Modes, In In Out and Out i.a.mcleod
2001-01-06  4:58 ` tmoran
2001-01-06 17:06   ` Robert Dewar
2001-01-06 19:50     ` tmoran
2001-01-06 20:31       ` Robert Dewar
2001-01-07  1:59     ` John English
2001-01-07  3:51       ` Robert Dewar
2001-01-08 12:06         ` dmitry6243
2001-01-09  4:32           ` Robert Dewar
2001-01-09 10:05             ` dmitry6243
2001-01-09  4:35           ` Robert Dewar
2001-01-09  9:58             ` dmitry6243
2001-01-09 14:13               ` Robert Dewar
2001-01-09 18:29                 ` dmitry6243
2001-01-09 19:55                   ` Robert Dewar
2001-01-10  0:47                     ` Brian Rogoff
2001-01-10 21:50                       ` Robert Dewar
2001-01-10  9:23                     ` dmitry6243
2001-01-10 21:46                       ` Robert Dewar
2001-01-11 11:46                         ` dmitry6243
2001-01-11 16:48                           ` Robert Dewar
2001-01-11 19:52                             ` Thierry Lelegard
2001-01-11 20:10                               ` Pascal Obry
2001-01-12  8:05                                 ` Florian Weimer
2001-01-12 13:31                               ` gasperon
2001-01-12 14:02                                 ` n_brunot
2001-01-12 17:26                                   ` charlet
2001-01-14 18:23                                     ` n_brunot
2001-01-14 21:05                                       ` Robert Dewar
2001-01-15  8:56                                         ` n_brunot
2001-01-12 11:05                             ` dmitry6243
2001-01-12 13:55                               ` Robert Dewar
2001-01-12 22:10                                 ` Dale Stanbrough
2001-01-13  1:13                                   ` Robert Dewar
2001-01-13 17:29                                 ` dmitry6243
2001-01-13 18:22                                   ` Robert Dewar
2001-01-13 22:32                                     ` Brian Rogoff
2001-01-14  6:02                                       ` Jeffrey Carter
2001-01-14 14:33                                         ` Robert Dewar
2001-01-14 18:14                                           ` Jeffrey Carter
2001-01-14 21:10                                             ` Robert Dewar
2001-01-14 20:45                                         ` Brian Rogoff
2001-01-14 14:23                                       ` Robert Dewar
2001-01-14 20:42                                         ` Brian Rogoff
2001-01-14 21:17                                           ` Robert Dewar
2001-01-15 20:57                                             ` Brian Rogoff
2001-01-15 16:25                                     ` dmitry6243
2001-02-02  7:06                                       ` mark_lundquist [this message]
2001-02-02 13:49                                         ` Multiple dispatch (was " dmitry6243
2001-01-16 12:22                                 ` Georg Bauhaus
2001-01-13  4:46                           ` Larry Kilgallen
     [not found]                           ` <93ko49$auq$1@nnrp1.deja.coOrganization: LJK Software <eiviJtYj+A7W@eisner.decus.org>
2001-01-13  6:00                             ` Robert Dewar
2001-01-11 21:38               ` mark_lundquist
2001-01-12  0:20                 ` John English
2001-01-12 13:57                   ` Robert Dewar
2001-01-12 20:34                     ` mark_lundquist
2001-01-13 18:06                       ` Brian Rogoff
2001-01-11 21:28             ` mark_lundquist
2001-01-12 12:35               ` dmitry6243
2001-01-12 21:22                 ` mark_lundquist
2001-01-13  1:16                   ` Robert Dewar
2001-02-02  5:42                     ` mark_lundquist
2001-02-02 14:55                       ` Stephen Leake
2001-02-02 20:08                         ` Robert Dewar
2001-02-05 15:00                           ` Stephen Leake
2001-01-13 21:26               ` Jean-Pierre Rosen
2001-01-11 21:24           ` mark_lundquist
2001-01-12 12:13             ` dmitry6243
2001-01-06 16:21 ` Jean-Pierre Rosen
2001-01-09 15:15   ` Thierry Lelegard
2001-01-10 21:53     ` Robert Dewar
2001-01-07 19:15 ` DuckE
2001-01-09 20:44 ` Laurent Guerby
2001-01-09 21:46   ` Florian Weimer
2001-01-10 21:57   ` Robert Dewar
2001-01-10 23:51     ` Tucker Taft
2001-01-11  4:23       ` Robert Dewar
2001-01-11 19:28     ` Laurent Guerby
2001-01-18 18:53 ` FAROOQATIF
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox