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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,d2a3144038a5a80e X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!d19g2000prh.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Question on types conversions - operations Date: Sat, 13 Jun 2009 10:24:22 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <4a33cb0b$0$2848$ba620e4c@news.skynet.be> NNTP-Posting-Host: 81.157.49.255 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1244913862 27504 127.0.0.1 (13 Jun 2009 17:24:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 13 Jun 2009 17:24:22 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d19g2000prh.googlegroups.com; posting-host=81.157.49.255; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.10, Ant.com Toolbar 1.3,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6460 Date: 2009-06-13T10:24:22-07:00 List-Id: On Jun 13, 5:59=A0pm, sjw wrote: > On Jun 13, 4:51=A0pm, Olivier Scalbert > wrote: > > > > > I have the following three types: > > =A0 =A0 =A0type Length is new Float; > > =A0 =A0 =A0type Time =A0 is new Float; > > =A0 =A0 =A0type Speed =A0is new Float; > > > Suppose I need to compute a speed given a length and a time. > > > =A0 =A0 =A0L: Length :=3D 100.0; > > =A0 =A0 =A0T: Time =A0 :=3D =A010.0; > > =A0 =A0 =A0S: Speed; > > > How to do that ? > > > With S :=3D Speed(Float(L) / Float(T)) ? Mmmm ... not nice. > > > With S :=3D Speed(L / Length(T)), I am also not satisfy as I convert a > > time in Length ... > > You could declare functions such as "*" (s : speed; t : time) return > length and of course "*" (t : time; s : speed) return length. > > Inside, you could use > =A0 return length (float (s) * float (t)); > > You could use speed'base, time'base but then what if one is > long_float? > > It's always seemed a lot of work for very little gain to me, I've > declared them as subtypes rather than types and left checking for the > right answer to unit test. But then, my world is all about logic and > there are far more enumerations than reals, and very few calculations. > Also, we tend to have coordinates (x, y) or (r, theta) so it's a lot > more useful to define "*", "+" etc. It would be brilliant if units checking could be built into the standard language... Cheers -- Martin