Path: utzoo!attcan!uunet!cs.utexas.edu!asuvax!ncar!ico!ism780c!news From: news@ism780c.isc.com (News system) Newsgroups: comp.lang.misc Subject: Re: Typing on units Message-ID: <40346@ism780c.isc.com> Date: 16 Mar 90 04:04:14 GMT References: <39941@ism780c.isc.com> <883@enea.se> Reply-To: marv@ism780.UUCP (Marvin Rubenstein) Organization: Interactive Systems Corp., Santa Monica CA Lines: 64 In article <883@enea.se> sommar@enea.se (Erland Sommarskog) writes: >Marvin Rubenstein (marv@ism780.UUCP) writes: I (Marv Rubinstein) talked about using units for an aid in error detection. [Erland Sommarskog responded] :The program below contains the same error and does not compile. :I have edited the error messages to stay below 80 columns. : : PROCEDURE Type_test IS : : TYPE Meter IS NEW Float; : TYPE Seconds IS NEW Float; : TYPE Meter_per_seconds IS NEW Float; : : x : Meter := 2.2; : s : Seconds := 3.3; : v : Meter_per_seconds; : : FUNCTION "/"(x : Meter; s : Seconds) RETURN Meter_per_seconds IS : BEGIN : RETURN Meter_per_seconds(x) / Meter_per_seconds(s); : END "/"; : : BEGIN : v := x / s; : v := x + s; : --------^A : ------------^B : --A:error: RM 3.3: base type of expression must be meter_per_seconds, line 5 : --B:error: RM 3.3: base type of expression must be meter_per_seconds, line 5 : END Type_test; : :In order to get division to work we had to define a function for it. :In fact we have to define a function of a similar kind for every operation :we want to make. 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 velocity = area/(time*distance); -- this is ok area = distance*distance; -- so is this time =velocity/distance; -- not good area =distance+distance; -- bad 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. Marv Rubinstein