comp.lang.ada
 help / color / mirror / Atom feed
From: Richard Riehle <richard@adaworks.com>
Subject: Re: Dimensions (was Re: Another Idea for Ada 20XX)
Date: Fri, 07 Dec 2001 19:52:53 -0800
Date: 2001-12-08T03:57:50+00:00	[thread overview]
Message-ID: <3C118E95.B5F013C8@adaworks.com> (raw)
In-Reply-To: 7KbQ7.13821$L51.28784@rwcrnsc54

Mark Lundquist wrote:

> "Richard Riehle" <richard@adaworks.com> wrote in message
> news:3C0EF0A0.9F42EDB4@adaworks.com...
>
> >
> >          package Metric_Number is
> >               type Metric_Type is private;
> >               -- export services for arithmetic on this type
> >               function "+"(L,  R : Metric_Type) return Metric_Type;
> >               -- more arithmetic and boolean functions
> >          private
> >               -- full definition for the Metric_Type;
> >               -- helper type to avoid recursion during implementation
> >          end Metric_Number;
>
> I have no idea what you're getting at with the "helper type to avoid
> recursion"... :-)

In implementing the infix operators for an experimental version of this
package, I found myself having to solve the problem of having the
full definition of the type as a numeric type itself.

> But in any case, the "good old-fashioned encapsulation"
> isn't enough (see below)...

> All these schemes that rely on hiding the representation have some serious
> weaknesses.  First of all, the public view is not scalar.  So
>
> (a) your type is not compatible with generics that take scalar formals --
> you are limited to formal private types; and

Granted.  One would be required to write one's own versions of the generics
and that would be a really bad idea.   Once again, I experimented with this
and ended up with some truly baroque code; workable but baroque.

> (b) you cannot declare subtypes with range constraints.

> (In my opinion (b) is by far the worse of these).

Actually, I think (a) is worse than (b).   One could define the package
as generic and include generic formal parameters for the range constraints.

> (c) it's way labor-intensive

In experimenting with this idea, I found that I could factor out some properties

to make it less labor-intensive than it might seem to be at first glance.
Nevertheless,
you are correct that it is more labor intensive than the more straigthforward
approach
orginally suggested.

> But the worst is still to come :-).  These schemes are quite brittle and
> unscalable, because:
>
> (d) you have to define all your visibly quasi-numeric operations on every
> combination of types for base and derived units, so you have a
> multiplicative explosion on your hands

In fact, I designed some generics to test this and found that the real problems
are: 1)  no notion of zero,  2) difficult to determine the 'Last and 'First, and

3) most other normally available attributes are not available.

> (e) , (f), and (g) from your posting.

I give you the points on those.

My suggestion, however, does work for some situations.  In experimenting with
this
idea, I decided to export the appropriate mathematical functions after
instantiating
the generic elementary functions within the body for the abstract number.   I
agree
that the final numeric package is very specialized but it seems to have a small
range of applicability for some circumstances.

Meanwhile, I am experimenting with other options that might permit a solution
without new language features.   I will report on my findings if they are at all

interesting.

Richard Riehle







  reply	other threads:[~2001-12-08  3:52 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-02 19:51 Another Idea for Ada 20XX Gautier Write-only-address
2001-12-02 22:36 ` James Rogers
2001-12-03 12:44   ` Marc A. Criley
2001-12-03 14:29     ` Larry Kilgallen
2001-12-04  0:25       ` Marc A. Criley
2001-12-04  1:40   ` Adrian Hoe
2001-12-04  1:56     ` Larry Kilgallen
2001-12-04 16:08       ` Wes Groleau
2001-12-04 17:48         ` Larry Kilgallen
2001-12-09 23:02           ` Nick Roberts
2001-12-10 16:22             ` Stephen Leake
2001-12-10 17:11               ` Wes Groleau
2001-12-10 20:30               ` Robert C. Leif, Ph.D.
2001-12-10 20:59                 ` Wes Groleau
2001-12-10 17:09             ` Wes Groleau
2001-12-10 17:32               ` Larry Kilgallen
2001-12-04 19:59         ` Vincent Marciante
2001-12-04 20:20           ` Wes Groleau
2001-12-04 22:18         ` Matthew Heaney
2001-12-06  4:14         ` Richard Riehle
2001-12-06 17:39           ` Wes Groleau
2001-12-07  0:55             ` Adrian Hoe
2001-12-07  9:01               ` Dmitry A. Kazakov
2001-12-07 11:49           ` Tarjei T. Jensen
2001-12-07 22:51           ` Dimensions (was Re: Another Idea for Ada 20XX) Mark Lundquist
2001-12-08  3:52             ` Richard Riehle [this message]
2001-12-08  5:28               ` Mark Lundquist
2001-12-08 18:59                 ` Matthew Heaney
2001-12-08 21:23               ` Wes Groleau
2001-12-09 22:15               ` Robert C. Leif, Ph.D.
2001-12-10 14:09             ` Ian
2001-12-03 14:56 ` Another Idea for Ada 20XX Mark Lundquist
2001-12-06 15:27   ` Philip Anderson
2001-12-07 22:51     ` Mark Lundquist
2001-12-10  9:01       ` 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