comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Reconsidering assignment
Date: Tue, 12 Jun 2007 10:31:34 +0200
Date: 2007-06-12T10:28:56+02:00	[thread overview]
Message-ID: <1v0wjynus2uj6$.b4qm8649j38o$.dlg@40tude.net> (raw)
In-Reply-To: 1181596329.198235.320830@w5g2000hsg.googlegroups.com

On Mon, 11 Jun 2007 14:12:09 -0700, Maciej Sobczak wrote:

> Still (heck, that doesn't seem to be the end of discussion :-) ), the
> earlier idea of expressing restrictions for subprogram parameters
> looks interesting to me. The point is that subprogram overloading
> operates on each parameter in isolation, whereas such restrictions
> could add the possibility of selecting more convoluted subsets of the
> whole relation.

(Note that by allowing this you allow multiple-dispatch, with its more than
linear number of alternatives)

> This is similar to treating the whole set of
> parameters as a single record type and then constraining this single
> record type for the purpose of overloading.
> If the restriction is based on run-time properties of parameters, then
> it doesn't provide anything that cannot be achieved with explicit if/
> else at the beginning of the subprogram.
> Consider:
> 
> procedure P(X, Y : Real) with X*X + Y*Y <= 1;
> procedure P(X, Y : Real);
>
> The idea was to have some assistance from the language for the proper
> selection of overloaded P (one is for arguments that fall withing the
> unit circle, and the other is for the rest).

This cannot work because overloading resolution happens at compile-time,
while the conditions of matching, in your case are general run-time
expressions.

BTW, a similar mechanism exists for entry point barriers:

   entry P (X, Y : Real) when <condition>;

Though, note that for very strong reasons <condition> may not depend on the
entry point arguments.

Another objection is that it is again preferences and it is undecidable.
Consider:

   procedure P(X, Y : Real) when Halt (X);
   procedure P(X, Y : Real);

and it is ambiguous:

   procedure P(X, Y : Real) when X in -1..10;;
   procedure P(X, Y : Real) when X in -10..1;

which one to choose when X is 0?

Yet another point: P is a polymorphic subprogram. Various overloading are
implementations of. The condition clause controls the choice. Does not it
remind you anything? Make Real a class!

A general software design objection is that this breaks encapsulation. The
idea of type is that constraints like X*X+Y*Y<1 should be property of a
type. When you move them to procedures, you loose OO/ADT decomposition.

> Here it doesn't give
> anything fundamentally new, this can be achieved with if/else in a
> single procedure.

IMO there is great need in a language support for compile-time user-defined
expressions and decomposition subprograms into compile- and run-time parts.
The most obvious case is dimensioned expressions.

> On the other hand, restrictions for compile-time properties might be
> more useful and can be for example an interesting optimization tool.

Well, Optimizations are optional, a proper choice of P is not.

If you wanted to have an optimization tool, you should make both Ps in your
example legal:

   procedure P(X, Y : Real) when Memory_Is_Low;
   procedure P(X, Y : Real) when A_CPU_Core_Is_Free;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2007-06-12  8:31 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-06 21:33 Reconsidering assignment Maciej Sobczak
2007-06-06 22:52 ` Ray Blaak
2007-06-07  7:15   ` Maciej Sobczak
2007-06-07 16:34     ` Ray Blaak
2007-06-07  7:10 ` Stefan Lucks
2007-06-07  7:32   ` Maciej Sobczak
2007-06-07 11:11     ` Stefan Lucks
2007-06-07 16:28   ` Ray Blaak
2007-06-07  9:27 ` Dmitry A. Kazakov
2007-06-07 16:54   ` contracted exceptions (was Re: Reconsidering assignment) Ray Blaak
2007-06-07 20:04     ` contracted exceptions Robert A Duff
2007-06-07 21:11       ` Ray Blaak
2007-06-07 23:44         ` Robert A Duff
2007-06-08  2:19       ` Randy Brukardt
2007-06-08  7:39         ` Dmitry A. Kazakov
2007-06-08  8:53           ` Ray Blaak
2007-06-08 12:08             ` Dmitry A. Kazakov
2007-06-08 17:31               ` Ray Blaak
2007-06-08 18:00                 ` Dmitry A. Kazakov
2007-06-08 18:20                   ` Georg Bauhaus
2007-06-08 18:56                     ` Dmitry A. Kazakov
2007-06-08 19:15                   ` Simon Wright
2007-06-09  0:14                     ` Randy Brukardt
2007-06-09  2:44                       ` Larry Kilgallen
2007-06-09  8:21                     ` Dmitry A. Kazakov
2007-06-09 12:32                       ` Simon Wright
2007-06-09 18:38                         ` Dmitry A. Kazakov
2007-06-09 21:04                           ` Simon Wright
2007-06-10  9:21                             ` Dmitry A. Kazakov
2007-06-10 11:49                               ` Simon Wright
2007-06-10 15:20                                 ` Dmitry A. Kazakov
2007-06-11  4:13                                   ` Ray Blaak
2007-06-11  7:58                                     ` Dmitry A. Kazakov
2007-06-11 17:06                                       ` Ray Blaak
2007-06-11 19:57                                         ` Dmitry A. Kazakov
2007-06-10 18:14                                 ` Georg Bauhaus
2007-06-10 18:12                               ` Georg Bauhaus
2007-06-11  7:55                                 ` Dmitry A. Kazakov
2007-06-11 14:15                         ` Bob Spooner
2007-06-11 15:14                           ` Georg Bauhaus
2007-06-11 15:20                             ` (see below)
2007-06-11 16:39                               ` Georg Bauhaus
2007-06-11 19:50                           ` Simon Wright
2007-06-08 11:26         ` Martin Krischik
2007-06-08 12:02         ` Robert A Duff
2007-06-08 11:22     ` contracted exceptions (was Re: Reconsidering assignment) Martin Krischik
2007-06-08 17:44       ` Ray Blaak
2007-06-08 12:10     ` contracted exceptions Robert A Duff
2007-06-08 15:56       ` Stefan Lucks
2007-06-08 20:27         ` Pascal Obry
2007-06-09  0:19           ` Randy Brukardt
2007-06-09 18:04             ` Robert A Duff
2007-06-09 18:37               ` Dmitry A. Kazakov
2007-06-09 20:43                 ` Robert A Duff
2007-06-10  9:21                   ` Dmitry A. Kazakov
2007-06-11 19:18                   ` Randy Brukardt
2007-06-12  6:55                     ` Jean-Pierre Rosen
2007-06-08 17:40       ` Ray Blaak
2007-06-09 18:14         ` Robert A Duff
2007-06-08 19:18       ` Simon Wright
2007-06-09 22:37   ` Reconsidering assignment Maciej Sobczak
2007-06-10  9:21     ` Dmitry A. Kazakov
2007-06-11  9:04       ` Maciej Sobczak
2007-06-11 13:09         ` Dmitry A. Kazakov
2007-06-11 18:57     ` Randy Brukardt
2007-06-11 21:12       ` Maciej Sobczak
2007-06-12  8:31         ` Dmitry A. Kazakov [this message]
2007-06-12  9:31           ` Georg Bauhaus
2007-06-12 10:03             ` Dmitry A. Kazakov
replies disabled

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