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-Thread: a07f3367d7,4ce5890331a5b529 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news3.google.com!news4.google.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Discriminants of tagged types Date: Wed, 27 Oct 2010 22:18:18 +0200 Organization: Ada @ Home Message-ID: References: <14314714-e92c-4036-9cbb-da8e72489261@h7g2000yqn.googlegroups.com> NNTP-Posting-Host: rx94L06a5qReYJRQTebs6g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 User-Agent: Opera Mail/10.63 (Win32) Xref: g2news1.google.com comp.lang.ada:14856 Date: 2010-10-27T22:18:18+02:00 List-Id: Le Wed, 27 Oct 2010 19:58:50 +0200, J-P. Rosen a =C3=A9= crit: > Reminder: > I1 : Integer; -- Can take all values of type Integer > I2 : Integer range 1..10; -- Constraint, restricts to value 1..10 > > with: > type Rec (D: Disc) is .... > > I must declare: > R1: Rec (1); -- Constraint, restricts to value 1 of discriminant. > > Wouldn't it be nice to have a variable that could hold all values of > type Rec? Naturally, this is written as: > R2: Rec; This is to be written as =E2=80=9CR2: Rec;=E2=80=9D only if there is no = way to know what = the discriminant should be. I may lack experiences (which is a never = ending story=E2=80=A6 (I like this old-movie's song)), so I may be wrong= : R2, as = it is a variable, will be assigned sooner or later, and this assignment = = will come with discriminant(s). I feel there is a way to infer this = constraint (possibly using nested blocks to ease, although SPARK does no= t = support it) in may be near to all cases. If ever R2 is assigned to a value which males it change its constraints,= = this isn't any more the same layout, so a bit not the same type. What = about saying this is no more the same object ? In procedure Any_Name is R1 : Rec (Expression_1); R2 : Rec (Expression_2); R : Rec; begin R :=3D R1; -- (1) R :=3D R2; -- (2) end; I feel the R of (1) terminates at (2) and at (2) a new R is born. Someon= e = may argue R is just assigned a new value. I feel there is two R here. Bu= t = this is not so much easy to have a clear idea here, as functional = programming aficionados will even argue =E2=80=9CI :=3D 1; I :=3D 2;=E2=80= =9D also create two = different things. I can easily handle polymorphism in my mind, when it comes with dynamic = = binding like with tagged types (see later for more on this). Here, I hav= e = difficulties to see polymorphism, as I see two different objects just = sharing the same storage (like with clumsy optimization). To me, it is a bit (I say a bit, there is a kind of level here) like doi= ng = : procedure Any_Name_2 is Time : Time_Type; begin Time :=3D Lunch_Time; -- Do something with dinner time (ex. adjust -- Time to get a meaningful lunch time). -- ... -- Let us suppose we never have to do -- computation on Lunch_Time interspersed -- with computations on Party_Time, so -- we decided to =E2=80=9Csave=E2=80=9D a variable and -- use one variable for both -- ... Time :=3D Party_Time; -- Do some computation on party time, idem. end; If we are to compute the exact time of lunch and the exact time of party= , = I would prefer to use two variables. When we do =E2=80=9CR :=3D R1; R :=3D R2;=E2=80=9D, what about checking = we are not doing = something similar to the above ? At least, that is like blurring subtypes. If we had : procedure Any_Name_3 is Astronomical_Distance : Distance_Type range 1 .. ; Every_Day_Distance : Distance_Type range 1 .. ; begin -- Would want to mix Astronomical_Distance and -- Every_Day_Distance in a same variable here ? null; end; Something similar : would want a parameter of a procedure, which could = receive either Subtype_1 or Subtype_2 ? This make sense with dynamic binding and dispatching parameter, because = we = have overloaded methods. But here, can we have a method which is = specialized for both ? When I talk about =E2=80=9Cmethods=E2=80=9D here, this can means any seq= uence of = instructions inside of a method. TBH, I will have to check if I used this in the past and why (I said all= = the above, while I am not sure I really never did it on my own side). -- = Si les chats miaulent et font autant de vocalises bizarres, c=E2=80=99es= t pas pour = les chiens.