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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!d25g2000prn.googlegroups.com!not-for-mail From: sjw Newsgroups: comp.lang.ada Subject: Re: Question on types conversions - operations Date: Sat, 13 Jun 2009 09:59:53 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <4a33cb0b$0$2848$ba620e4c@news.skynet.be> NNTP-Posting-Host: 82.20.239.89 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1244912394 22906 127.0.0.1 (13 Jun 2009 16:59:54 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 13 Jun 2009 16:59:54 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d25g2000prn.googlegroups.com; posting-host=82.20.239.89; posting-account=_RXWmAoAAADQS3ojtLFDmTNJCT0N2R4U User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/525.28.3 (KHTML, like Gecko) Version/3.2.3 Safari/525.28.3,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6459 Date: 2009-06-13T09:59:53-07:00 List-Id: 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 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.