comp.lang.ada
 help / color / mirror / Atom feed
From: Patrick Hohmeyer <pi3_1415926536@yahoo.ca>
Subject: Re: Another Idea for Ada 20XX
Date: Sun, 2 Dec 2001 16:19:08 -0500
Date: 2001-12-02T16:19:08-05:00	[thread overview]
Message-ID: <ezwO7.1091$iF3.275822@news20.bellglobal.com> (raw)
In-Reply-To: 3C0A5054.E74A82E7@worldnet.att.net

James Rogers wrote :

> In scientific terms a measurement is done in terms of some unit.
> For instance, distance is in meters, microns, feet or furlongs.
> Speed is then calculated as a distance per unit time. Acceleration
> is the second derivative of speed.

Acceleration is the second derivative of *distance*. ;-)

> The advantage for the software developer is in the usage:
> 
> Vehicle_Speed : Speed;
> Track_Distance : Meters;
> Lap_Time : Hours;
> 
> Speed := Track_Distance / Lap_Time;
> 
> This approach would allow the appropriate mixing of data types, which
> is currently forbidden by Ada, in a meaningful and correct manner.
> 

Hmm, this can very easly be achived with overloading of "/" :

function "/" (Dist : Meters; Time : Hours) return Speed is
--...

And I have a huge problem with the name of the type Speed.
Speed is not a unit, but an concept.

Would be more interesting :

type Distance is basic concept with basic unit Meters;
type Time is basic concept with basic unit Seconds;
type Speed is concept (Distance / Time);

Vehicle_Speed : Speed; -- ok
Track_Distance1 : Meters; -- ok
Track_Distance2 : Meters := 12.5; -- ok
Lap_Time1 : Time; -- ok
Lap_Time2 : Time := Seconds(34.3); -- ok

Lap_Time3 : Time := 34.3; 
-- 2 possibles reactions :
-- 1. won't compile as the unit isn't specified !!! (my favor)
-- 2. uses the basic unit for the concept (Seconds)
--     (but generates a compiler warning)

Vehicle_Speed := Track_Distance1 / Lap_Time1; --ok

Internally a concept type would be something as
record
  Value : Double;
  Unit : Unit_type;
end record;

Unit somehow describes how we can transform the value
into a value in the basic units. (an access to a function?)
and vice-versa.

The great part are unit extentions :

type Hours is Time unit 3600 Seconds;

S : Seconds := 3954.3;
H : Hours := S;

And the compiler would automagicly put 3954.3 / 3600 into H.
As would the cast Hours(S) return 3954.3 / 3600;

Especially for Space programs between US and Europe this would
be a *huge* benefit.
Just declare :

type Inchs is Distance unit x Meters;

and the compiler will do all unit conversions for you.

And of course :
type Temperature is basic concept with basic unit Kelvin;
type Celsius is Temperature unit 1 Kelvin + 273.15;

And a non-basic concept : 
type Mass is basic concept with basic unit Kilogram;
type Acceleration is concept Speed / Time;
type Force is concept Mass * Acceleration;

type Newton is Force unit 1 (Kilogram * Meters * Seconds**(-2)); 
(Note that :
  type Newton is Force unit 1
  (Kilogram * Meters * Seconds**(-1) * Hours**(-1));
would also be syntaxly correct, you can mix 2 time units in a
composed unit.)

I think that this could be fun, but may be to complicated to
implement and if you really need it, can already be done with
a record and an access to fonction for the unit type,
and a lot of overloaded functions.

But what do you think ?

-- 
Patrick Hohmeyer



  parent reply	other threads:[~2001-12-02 21:19 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-02 16:01 Another Idea for Ada 20XX James Rogers
2001-12-02 16:38 ` Preben Randhol
2001-12-02 22:26   ` James Rogers
2001-12-02 21:19 ` Patrick Hohmeyer [this message]
2001-12-02 21:26 ` Lutz Donnerhacke
2001-12-02 23:49   ` Patrick Hohmeyer
2001-12-03  6:06     ` Wilhelm Spickermann
2001-12-03  8:58     ` Lutz Donnerhacke
2001-12-03 13:40     ` Thomas Koenig
2001-12-03  0:21 ` Robert C. Leif, Ph.D.
2001-12-03  0:35 ` Robert Dewar
2001-12-03  1:33   ` James Rogers
2001-12-03 12:34     ` Dirk Dickmanns
2001-12-04 19:02       ` Unit handling (was: Another Idea for Ada 20XX) Wilhelm Spickermann
2001-12-03 14:56 ` Another Idea for Ada 20XX Mark Lundquist
2001-12-03 15:12   ` Lutz Donnerhacke
2001-12-03 21:13     ` Dimensionality Checking (Ada 20XX) Nick Roberts
2001-12-04 14:00       ` Dmitry A. Kazakov
2001-12-06 19:52         ` Britt Snodgrass
2001-12-06 20:55           ` Mark Lundquist
2001-12-06 22:38           ` Wes Groleau
2001-12-06 23:12             ` Mark Lundquist
2001-12-07 14:36               ` Wes Groleau
2001-12-07  9:37           ` Dmitry A. Kazakov
2001-12-07 22:51           ` Mark Lundquist
2001-12-03 17:00   ` Another Idea for Ada 20XX chris.danx
  -- strict thread matches above, loose matches on Subject: below --
2001-12-02 19:51 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-03 14:56 ` Mark Lundquist
2001-12-06 15:27   ` Philip Anderson
2001-12-07 22:51     ` Mark Lundquist
2001-12-10  9:01       ` Dmitry A. Kazakov
2001-12-02 21:24 Gautier Write-only-address
2001-12-03 14:56 ` Mark Lundquist
replies disabled

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