🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #896

Re: Typing on units

#896
From: Erland Sommarskog
Date: Mon, 19 Mar 1990 21:59
55 lines
2638 bytes
Marvin Rubenstein (marv@ism780.UUCP) writes:
>  I (Marv Rubinstein) talked about using units for an aid in error
>   detection.

Where upon I suggested a method of implementing this in Ada.

Marvin responds:
>The language I had in mind was more like this.
>
>     units
>       m              -- mass
>       l              -- length
>       t              -- time
>       f = m*l/(t*t)  -- force
>     end units
>     data
>       velocity :real, unit l/t;
>       distance :real, unit l;
>       time     :real, unit t;
>       area     :real, unit l*l;
>     end data
>
>The actual language that I was refering to also allowed conversion
>constants (e.g. for feet to meters) to appear in the units declarations.
>Thus, conversions were inserted automatically by the compiler.  What you are
>suggesting would, in my opinion, make the programming of a large scientific
>computation almost impossible.

I was fully aware of what I proposed was not really what you wanted,
on the other hand, I don't see any important conceptual difference
in your out-line. Your notation is far more compact that the Ada
package you would have to write, but once you would had it done,
you could go ahead and program your computation. And the package
would still be there the next time. Or did I miss something? What 
in my proposal would make your program impossible to write?
  The gain, as I see it, with the Ada solution is that we are saved
another language with some quite special features that are not of
general interest, but instead we implement those features with
general mechanisms. After all, there are plenty of applications
where units plays about no role at all.

There is one point where Ada fails, though. If you declare:
    US_distance         : Feet;
    Real_world_distance : Meter;
you cannot simply write:
   Real_world_distance := US_distance;
but have to rely on a conversion routine:
   Real_world_distance := Feet_to_meter(US_distance);
since Ada doesn't provide overloadable assignment. What's
worse is that:
   Real_world_distance := Meter(US_distance);
is a legal, but does only move the bits from the right-hand
side to the other, and thus constitute a trap you may fall in.
-- 
Erland Sommarskog - ENEA Data, Stockholm - sommar@enea.se
Technical Details
Message-ID: <907@enea.se>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!sunic!enea!sommar
References: <39941@ism780c.isc.com> <883@enea.se> <40346@ism780c.isc.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!sunic!enea!sommar
From: sommar@enea.se (Erland Sommarskog)
Newsgroups: comp.lang.misc
Subject: Re: Typing on units
Message-ID: <907@enea.se>
Date: 19 Mar 90 21:59:49 GMT
References: <39941@ism780c.isc.com> <883@enea.se> <40346@ism780c.isc.com>
Organization: Enea Data AB, Sweden
Lines: 55