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.0 required=5.0 tests=BAYES_05, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7009ff26a584c028,start X-Google-Attributes: gid103376,public Path: g2news1.google.com!news2.google.com!proxad.net!freenix!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Duncan Sands Newsgroups: comp.lang.ada Subject: Dimensions and fixed point types Date: Wed, 9 Jun 2004 09:11:39 +0200 Organization: Cuivre, Argent, Or Message-ID: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1086765133 36476 212.85.156.195 (9 Jun 2004 07:12:13 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Wed, 9 Jun 2004 07:12:13 +0000 (UTC) To: Return-Path: User-Agent: KMail/1.6.2 Content-Disposition: inline X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:1277 Date: 2004-06-09T09:11:39+02:00 Fixed point types have a remarkable property: you can multiply any two of them to get a third. You can multiply apples and oranges and get bananas. This goes against type safety. Suppose I have several fixed point types, for example type Price is delta 0.01 digits ...; type Volume is delta 1.0 digits ...; type Value is delta 0.01 digits ...; Then all possible multiplications are legal. By declaring some multiplications abstract, I can remove unwanted operations, and just keep the ones I want, for example Price * Volume = Value. (This is already a lot of operations to remove!). However if somewhere else I define type Oranges is delta ... digits ...; then I automagically get a whole bunch of new operations (Orange * Value = Price etc) that I don't want. To be safe I'd need to remove them all too - it is never ending. This makes fixed point types almost useless in a dimensions system, or whenever you want to catch incorrect operations based on type. Maybe there is a trick I am missing though. Can anyone see a way to use fixed point types safely in a setting where multiplying objects of the wrong type would be fatal? Also, why were things done this way? It seems to me that a much better approach would be to say that multiplication between different fixed point types is NOT automatically defined, but can be obtained by writing something like this: function "*" (Left : Apples; Right : Oranges) return Banana; pragma Import (Intrinsic, "*"); Thanks for any comments, Duncan.