Ada's derived types and units of measure

Types in programming languages cannot model many properties of real world objects and quantities. Consequently, many errors resulting from the inconsistent usage of program objects representing real world objects and quantities cannot be detected automatically. For example, the real variables PRICE and WEIGHT, representing the price of diesel fuel and the weight of a person, may be inadvertently added, giving a non‐sensical value; such an error cannot be detected by a compiler. The programming language Ada introduces the concept of derived types to tackle this problem. An alternative solution to this problem is the incorporation of units of measure as a new data attribute. Derived types only partially solve the problem of detecting the inconsistent usage of objects; some valid usages of objects are also not allowed. Moreover, the solution is inelegant and inconvenient to use. On the other hand, specification of units of measure solves the problem elegantly and conveniently. The two solutions are compared and analysed. Several ways to implement units of measure in Ada are examined.

[1]  David B. Loveman,et al.  Incorporation of units into programming languages , 1978, CACM.

[2]  Narain H. Gehani Databases and Units of Measure , 1982, IEEE Transactions on Software Engineering.

[3]  Narain H. Gehani,et al.  Units of Measure as a Data Attribute , 1977, Comput. Lang..

[4]  Edsger W. Dijkstra,et al.  DoD-I: the summing up , 1978, SIGP.

[5]  R. C. Pankhurst,et al.  Dimensional Analysis and Scale Factors , 1964 .