C strongly typed?

Magnus Rimvall rimvallm at jupiter.crd.ge.com
Wed Mar 14 02:59:04 AEST 1990


In article <39941 at ism780c.isc.com> marv at ism780.UUCP (Marvin Rubenstein) writes:
>I am unaware of any commonly available language that prevents this form of
>mistake.  Look at the following:
>
>  double distance;
>  double time;
>  double velocity;
>
>  velocity = distance/time;  /* this makes sense */
>  velocity = distance+time;  /*  I mixed 'apples' and 'oranges' and produced
>				 a lemon :-) */
>
>I did read a paper (sorry, I don't have the reference) describing a language
>that allowed one to augment the the type declaration with a units declaration
>so as to be able to catch errors of this form.
>
>   Marv Rubinstein

The problem with mismatching units is particularly bothersome in
the area of continuous system simulation, where the whole
program/model consists of equations taking units.  Some
simulation programs do indeed support unit checking (a new version
of the simulation language CSSL-IV which supported unit
declarations/checks was announced some time ago - this might have
been the paper Marv read).

The task of unit tests is, at least in the USA, only half the
battle. Until the metric system is adopted, we would also need
automatic scaling of units (even the *dumbest* unit test unit
could learn that a KW is equal to 1000 W, without knowing what a
W itself is. Not even intelligent human beings can know for sure
how much a "ton" or a "gallon" really is ... but this does not really
belong in comp.*, so flame me in sci.misc).

Magnus Rimvall

Disclaimer: This letter does not necessarily reflect the opinions
of anybody else (though they should)



More information about the Comp.lang.c mailing list