From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,791ecb084fdaba75 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-10-04 13:12:25 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!swrinde!elroy.jpl.nasa.gov!lll-winken.llnl.gov!enews.sgi.com!wdl1!dst17!mab From: mab@dst17.wdl.loral.com (Mark A Biggar) Subject: Re: Types with physical dimension Message-ID: <1994Oct4.194510.22580@wdl.loral.com> Sender: news@wdl.loral.com Organization: Loral Western Development Labs References: Date: Tue, 4 Oct 1994 19:45:10 GMT Date: 1994-10-04T19:45:10+00:00 List-Id: In article eachus@spectre.mitre.org (Robert I. Eachus) writes: >In article sal714@rs710.gsfc.nasa.gov (Stephen A. Leake) writes: > > Very early on, I started to write a package that enforced > > dimensionality; I defined METERS, METERS_PER_SECOND, etc. I quickly > > discovered that even simple equations need up to cubic dimensions, > > in all combinations of length, mass and time. Defining all these > > types and the associated operators was far too time-consuming to be > > worth it. So now I rely on code reviews and careful testing. > > The moral; strong typing is nice, but is no substitute for careful design > > and thorough testing. > Paul Hilfinger did a nice paper on using discriminants to check >dimensionality. I don't have the paper in front of me but it works >something like this: > type Measure(Length,Mass,Time: Integer) is record > Value: Float; > end record; > subtype Meters is Measure(1,0,0); > subtype Kilograms is Measure(0,1,0); > subtype Time is Measure(0,0,1); > ...etc. > The only problem I had was with square roots. I thought about >changing the package to double all the dimensional values, so length >would be (2,0,0), but I never did. Unless you are doing some really wierd physics, the square root of a base dimension doesn't really make any sense. So just raise CONSTRAINT_ERROR whenever any of the dimensions is odd. -- Mark Biggar mab@wdl.loral.com