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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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-7-bit Path: g2news2.google.com!news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Question on types conversions - operations Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <4a33cb0b$0$2848$ba620e4c@news.skynet.be> Date: Sat, 13 Jun 2009 18:58:40 +0200 Message-ID: <1jbptobad4t8l$.wfr99mkqhovj$.dlg@40tude.net> NNTP-Posting-Date: 13 Jun 2009 18:58:41 CEST NNTP-Posting-Host: 8932fc33.newsspool4.arcor-online.net X-Trace: DXC=Ye70JEAb=O@^B]`=U:WelB4IUK On Sat, 13 Jun 2009 17:51:17 +0200, Olivier Scalbert wrote: > I have the following three types: > type Length is new Float; > type Time is new Float; > type Speed is new Float; > > Suppose I need to compute a speed given a length and a time. > > L: Length := 100.0; > T: Time := 10.0; > S: Speed; > > How to do that ? > > With S := Speed(Float(L) / Float(T)) ? Mmmm ... not nice. > > With S := Speed(L / Length(T)), I am also not satisfy as I convert a > time in Length ... Once you have said 'A', you have to say 'B': function "/" (Left, Right : Length) return Length is abstract; function "/" (Left, Right : Time) return Length is abstract; function "/" (Left, Right : Speed) return Length is abstract; function "/" (Left : Length; Right : Time) return Speed; The first three disallow illegal operations on Length, Time and Speed. The body of "/" is function "/" (Left : Length; Right : Time) return Speed is begin return Speed (Float (Left) / Float (Right)); end "/"; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de