comp.lang.ada
 help / color / mirror / Atom feed
From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: Discriminants of tagged types
Date: Wed, 27 Oct 2010 22:18:18 +0200
Date: 2010-10-27T22:18:18+02:00	[thread overview]
Message-ID: <op.vk830spfule2fv@garhos> (raw)
In-Reply-To: ia9p8t$5ue$1@news.eternal-september.org

Le Wed, 27 Oct 2010 19:58:50 +0200, J-P. Rosen <rosen@adalog.fr> a é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 “R2: Rec;” only if there is no way to know what  
the discriminant should be. I may lack experiences (which is a never  
ending story… (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 not  
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 := R1; -- (1)
       R := R2; -- (2)
    end;

I feel the R of (1) terminates at (2) and at (2) a new R is born. Someone  
may argue R is just assigned a new value. I feel there is two R here. But  
this is not so much easy to have a clear idea here, as functional  
programming aficionados will even argue “I := 1; I := 2;” 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 have  
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 doing  
:

    procedure Any_Name_2
    is
       Time : Time_Type;
    begin
       Time := 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 “save” a variable and
       -- use one variable for both
       -- ...
       Time := 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 “R := R1; R := R2;”, 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 .. <big value>;
       Every_Day_Distance : Distance_Type range 1 .. <humanized value>;
    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 “methods” here, this can means any sequence 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’est pas pour  
les chiens.



  reply	other threads:[~2010-10-27 20:18 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-27 12:16 Discriminants of tagged types Maciej Sobczak
2010-10-27 12:34 ` Ludovic Brenta
2010-10-27 13:19   ` Dmitry A. Kazakov
2010-10-27 13:52     ` Robert A Duff
2010-10-27 14:12       ` Dmitry A. Kazakov
2010-10-27 13:44 ` Robert A Duff
2010-10-27 15:06   ` Adam Beneschan
2010-10-27 15:58     ` Yannick Duchêne (Hibou57)
2010-10-27 16:35       ` Vinzent Hoefler
2010-10-27 17:58       ` J-P. Rosen
2010-10-27 20:18         ` Yannick Duchêne (Hibou57) [this message]
2010-10-27 20:26       ` Adam Beneschan
2010-10-27 22:07         ` Yannick Duchêne (Hibou57)
2010-10-27 22:42           ` Adam Beneschan
2010-10-27 15:13   ` Maciej Sobczak
2010-10-27 16:02     ` Yannick Duchêne (Hibou57)
2010-10-27 21:13       ` Maciej Sobczak
2010-10-27 21:23         ` Ludovic Brenta
2010-10-28  8:38           ` Maciej Sobczak
2010-10-27 21:25         ` Vinzent Hoefler
2010-10-28  7:53         ` Dmitry A. Kazakov
2010-10-28  8:50           ` Maciej Sobczak
2010-10-28 10:28             ` Dmitry A. Kazakov
2010-10-28 17:48             ` Yannick Duchêne (Hibou57)
2010-10-29 18:59             ` Vinzent Hoefler
2010-10-30 21:05               ` Maciej Sobczak
2010-10-30 21:21                 ` Vinzent Hoefler
2010-10-30 22:01                   ` Yannick Duchêne (Hibou57)
2010-10-31 16:20                   ` Maciej Sobczak
2010-10-31 17:04                     ` Yannick Duchêne (Hibou57)
2010-10-31 18:36                     ` Shark8
2010-10-31 21:06                       ` Maciej Sobczak
2010-11-01  0:44                         ` Shark8
2010-11-01  9:41                           ` Maciej Sobczak
2010-10-27 16:06     ` Robert A Duff
2010-10-27 16:34       ` Yannick Duchêne (Hibou57)
2010-10-27 21:05       ` Maciej Sobczak
2010-10-28  0:35         ` Robert A Duff
2010-10-28  8:55           ` Maciej Sobczak
2010-10-27 21:28       ` Simon Wright
2010-10-27 13:54 ` J-P. Rosen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox