* "end of declaration"
@ 2021-02-10 18:39 Mehdi Saada
2021-02-10 19:06 ` AdaMagica
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Mehdi Saada @ 2021-02-10 18:39 UTC (permalink / raw)
can someone explain in simple terms what are the rules for types' "end of declaration" ?
I define a type in the private part of the package, and in the body I clone it (type t_proba2 is new t_proba) to benefit from its predefined operations... since it's a fixed point type I need to, or bam ! recursion... also I want the accuracy etc to stay the same so I would do the same for floating point types too.
type T_Proba is delta 0.00001 range 0.0 .. 1.0;
for T_Proba'Small use 0.00001;
package body P_Proba2 is
type t_proba2 is new T_Proba2;
-- type t_proba2 can't be use before the end of its declaration
package Point_Fixe_io is new Ada.Text_Io.Fixed_IO(T_Proba);
so I rather defined a different type with the same specifications. ugly.
no nicer way to access predefined operations for these cases ?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: "end of declaration"
2021-02-10 18:39 "end of declaration" Mehdi Saada
@ 2021-02-10 19:06 ` AdaMagica
2021-02-10 19:21 ` Egil H H
2021-02-10 20:59 ` Shark8
2 siblings, 0 replies; 7+ messages in thread
From: AdaMagica @ 2021-02-10 19:06 UTC (permalink / raw)
0012...@gmail.com schrieb am Mittwoch, 10. Februar 2021 um 19:40:00 UTC+1:
> package body P_Proba2 is
> type t_proba2 is new T_Proba2;
> -- type t_proba2 can't be use before the end of its declaration
I don't unDerstand. DeclAration ends herE.
Why do you use a derived type?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: "end of declaration"
2021-02-10 18:39 "end of declaration" Mehdi Saada
2021-02-10 19:06 ` AdaMagica
@ 2021-02-10 19:21 ` Egil H H
2021-02-10 19:31 ` Mehdi Saada
2021-02-10 20:59 ` Shark8
2 siblings, 1 reply; 7+ messages in thread
From: Egil H H @ 2021-02-10 19:21 UTC (permalink / raw)
On Wednesday, February 10, 2021 at 7:40:00 PM UTC+1, 0012...@gmail.com wrote:
>
> I define a type in the private part of the package, and in the body I clone it (type t_proba2 is new t_proba) to benefit from its predefined operations...
What? The predefined operations are already visible in the body.
> since it's a fixed point type I need to, or bam ! recursion...
huh?
> package body P_Proba2 is
> type t_proba2 is new T_Proba2;
> -- type t_proba2 can't be use before the end of its declaration
This is because of a typo... Try
type t_proba2 is new T_Proba;
instead. Except that you don't need this derived type, so just delete the line.
> package Point_Fixe_io is new Ada.Text_Io.Fixed_IO(T_Proba);
...and here you're using the original type anyway, so...
> no nicer way to access predefined operations for these cases ?
Just call them, they are visible...
--
~egilhh
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: "end of declaration"
2021-02-10 19:21 ` Egil H H
@ 2021-02-10 19:31 ` Mehdi Saada
2021-02-10 21:08 ` Shark8
0 siblings, 1 reply; 7+ messages in thread
From: Mehdi Saada @ 2021-02-10 19:31 UTC (permalink / raw)
@øþĸłµ¤££%¤µ]ßĐÐß»¢ĐŊГ¢Ŋ@ÐĐ@ßĐÆ#{#[~#{#Þ]!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I hope it will stop happening...
otherwise, operations for t_proba are redefined in the visible (and body) part so recursion will occur.
But I saw what I should have done:
type t_proba is private;
private
type Nombre is ... with the representation clause
type t_proba is new nombre;
I'm ashamed I didn't come up with that before...
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: "end of declaration"
2021-02-10 18:39 "end of declaration" Mehdi Saada
2021-02-10 19:06 ` AdaMagica
2021-02-10 19:21 ` Egil H H
@ 2021-02-10 20:59 ` Shark8
2 siblings, 0 replies; 7+ messages in thread
From: Shark8 @ 2021-02-10 20:59 UTC (permalink / raw)
On Wednesday, February 10, 2021 at 11:40:00 AM UTC-7, 0012... wrote:
> can someone explain in simple terms what are the rules for types' "end of declaration" ?
>
> I define a type in the private part of the package, and in the body I clone it (type t_proba2 is new t_proba) to benefit from its predefined operations... since it's a fixed point type I need to, or bam ! recursion... also I want the accuracy etc to stay the same so I would do the same for floating point types too.
>
> type T_Proba is delta 0.00001 range 0.0 .. 1.0;
> for T_Proba'Small use 0.00001;
>
> package body P_Proba2 is
> type t_proba2 is new T_Proba;
> -- type t_proba2 can't be use before the end of its declaration
> package Point_Fixe_io is new Ada.Text_Io.Fixed_IO(T_Proba);
>
> so I rather defined a different type with the same specifications. ugly.
> no nicer way to access predefined operations for these cases ?
Use more meaningful names if you can.
You had "Type K is new K", which is obvious nonsense.
Considering the context, I think something like
> type Probability is delta 0.00001 range 0.0 .. 1.0;
> for Probability'Small use 0.00001;
and
> type Internal_Probability is new Probability;
would be much better readability-/maintainability-wise
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: "end of declaration"
2021-02-10 19:31 ` Mehdi Saada
@ 2021-02-10 21:08 ` Shark8
2021-02-10 22:43 ` Niklas Holsti
0 siblings, 1 reply; 7+ messages in thread
From: Shark8 @ 2021-02-10 21:08 UTC (permalink / raw)
> otherwise, operations for t_proba are redefined in the visible (and body) part so recursion will occur.
What?
No, "Type J is new K" gives you a completely new type.
To use a function that requires a K-value with a J-value you have to explicitly convert; given "Steve : J" and "-"(Right: K) return K, you would have to use -(K(Steve)) to call the unary-minus for K.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: "end of declaration"
2021-02-10 21:08 ` Shark8
@ 2021-02-10 22:43 ` Niklas Holsti
0 siblings, 0 replies; 7+ messages in thread
From: Niklas Holsti @ 2021-02-10 22:43 UTC (permalink / raw)
On 2021-02-10 23:08, Shark8 wrote:
>> otherwise, operations for t_proba are redefined in the visible
>> (and body) part so recursion will occur.
> What?
> No, "Type J is new K" gives you a completely new type.
Yes, but J inherits all primitive operations of K. And you can
type-convert between J and K with no loss of information.
> To use a function that requires a K-value with a J-value you have to
> explicitly convert; given "Steve : J" and "-"(Right: K) return K, you
> would have to use -(K(Steve)) to call the unary-minus for K.
If the "-" function is a primitive operation of K, there is an identical
inherited operation for J. If the "-" with a K-parameter is not
primitive for K, it is not inherited by J, and a J-value j must be
converted to a K-value before that "-" is called: - K(j).
You can override the inherited "-" with a new operation, specific to J.
Within that operation, calling "-" on a J-value j would make it
recursive. The K-operation can be called with - K(j) and that will not
be a recursive call.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-02-10 22:43 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 18:39 "end of declaration" Mehdi Saada
2021-02-10 19:06 ` AdaMagica
2021-02-10 19:21 ` Egil H H
2021-02-10 19:31 ` Mehdi Saada
2021-02-10 21:08 ` Shark8
2021-02-10 22:43 ` Niklas Holsti
2021-02-10 20:59 ` Shark8
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox