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=unavailable autolearn_force=no version=3.4.4 Path: buffer2.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!1.eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: hreba Newsgroups: comp.lang.ada Subject: Re: Incompatible types for array conversion Date: Wed, 22 Jul 2015 10:22:19 -0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net WWJDAJ1y9jAXTDgGobZwnAyiK6emFs7DnwwbXj3f3jP8BgrX0h Cancel-Lock: sha1:0NOhNwLpDDabPrjD1kI8/W6HvhI= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: Xref: number.nntp.giganews.com comp.lang.ada:194290 Date: 2015-07-22T10:22:19-03:00 List-Id: On 07/22/2015 10:00 AM, hreba wrote: > On 07/22/2015 02:20 AM, Niklas Holsti wrote: >> On 15-07-22 04:19 , hreba wrote: >>> I have a generic vector package: >>> >>> generic >>> dim: positive; >>> type Real is digits <>; >>> package Vectors is >>> type Vector is array (1..dim) of Real; >>> function "*" (a: Vector; b: Real) return Vector; >>> end Vectors; >>> >>> In another package I want to model the definition of a (physical) >>> position vector by its direction and module: >>> >>> package Basic is >>> type Real is new Interfaces.IEEE_Float_64; >>> type Length is new Real; >>> >>> package Positions is new Gen.Vectors (3, Length); >>> package Directions is new Gen.Vectors (3, Real); >>> >>> subtype Position is Positions.Vector; >>> subtype Direction is Directions.Vector; >>> >>> function "*" (l: Direction; r: Length) return Position; >>> end Basic; >>> >>> Now my attempt to define this function: >>> >>> function "*" (l: Direction; r: Length) return Position is >>> begin return Positions."*"(Position(l), r); end "*"; >>> >>> gets me the error message in the subject line. >>> >>> Do I have to convert the vector element by element in a loop or is there >>> a more elegant way? >> >> The conversion is rejected because of the conversion condition in RM 4.6 >> (24.5/2): "The component subtypes shall statically match". The component >> (sub)types are Real and Length, which are different types, although >> Length is derived from Real. If you change the declaration of Length >> to be >> >> subtype Length is Real; >> >> the conversion becomes legal. >> > > Thanks a lot for the hint! > Well, I was a little too fast with my response. It works, but it is not what I need. I use type Real for physical dimensionless quantities and Length for lengths. They must be incompatible, you cannot add them. So I came up with a new version of my function: function "*" (l: Direction; r: Length) return Position is begin return Positions."*" (Position'(Length(l(1)), Length(l(2)), Length(l(3))), r); end "*"; (Thanks God I am working with classical physics and not string theory with its 26 dimensions.) -- Frank Hrebabetzky +55 / 48 / 3235 1106 Florianopolis, Brazil