comp.lang.ada
 help / color / mirror / Atom feed
* how to force the Small aspect of a new type derived from the generic formal type ?
@ 2018-01-24 19:16 Mehdi Saada
  2018-01-25  3:30 ` Randy Brukardt
  0 siblings, 1 reply; 7+ messages in thread
From: Mehdi Saada @ 2018-01-24 19:16 UTC (permalink / raw)


Yet again... Look at this ! The teacher said: use Small aspect/representation clause, and somewhere else he said to make the package generic. I did both...

generic
   type Modele is delta <> ;
package Proba is
   type T_proba is new MODELE range 0.1..1.0 with Small => Modele'Delta;

gives us: representation item not allowed for generic type

I don't get it, since the RM states:
formal_complete_type_declaration ::= 
    type defining_identifier[discriminant_part] is formal_type_definition
        [aspect_specification];

Doing it otherwise:   type Modele is delta <>  with SMALL => MODELE'DELTA;
gives a more precise warning: aspect "Small" not allowed for formal type declaration.

How do I do that ? Forcing the representation of a new type derived from the generic formal type ?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to force the Small aspect of a new type derived from the generic formal type ?
  2018-01-24 19:16 how to force the Small aspect of a new type derived from the generic formal type ? Mehdi Saada
@ 2018-01-25  3:30 ` Randy Brukardt
  2018-01-25 12:54   ` Mehdi Saada
  2018-01-25 18:35   ` G. B.
  0 siblings, 2 replies; 7+ messages in thread
From: Randy Brukardt @ 2018-01-25  3:30 UTC (permalink / raw)


"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:1aaa851e-495a-4dd4-8db7-0fd84ee8225f@googlegroups.com...
> Yet again... Look at this ! The teacher said: use Small 
> aspect/representation clause, and somewhere else he said to make the 
> package generic. I did both...
>
> generic
>   type Modele is delta <> ;
> package Proba is
>   type T_proba is new MODELE range 0.1..1.0 with Small => Modele'Delta;
>
> gives us: representation item not allowed for generic type

That's just what the error message says; you can't use most representation 
aspects on a type derived from a generic formal type.

Even if you were not in a generic unit, you can't usually put representation 
aspects on a derived type (they usually have to match the original type). 
The representation aspects have to go on the original type (the one passed 
into the generic unit).

...
> How do I do that ? Forcing the representation of a new type derived from 
> the generic formal type ?

You can't do that; the derived type has to have the same representation as 
the formal type.

Either the teacher is asking for the impossible (which, unfortunately IS 
possible), or you misunderstood the request.

                          Randy.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to force the Small aspect of a new type derived from the generic formal type ?
  2018-01-25  3:30 ` Randy Brukardt
@ 2018-01-25 12:54   ` Mehdi Saada
  2018-01-26  4:38     ` Randy Brukardt
  2018-01-26 11:13     ` Alejandro R. Mosteo
  2018-01-25 18:35   ` G. B.
  1 sibling, 2 replies; 7+ messages in thread
From: Mehdi Saada @ 2018-01-25 12:54 UTC (permalink / raw)


> Either the teacher is asking for the impossible

Actually the teacher isn't asking to do that: he asked at some point to make it generic, at and at another, to force the Small. I assumed we could do both.

> you can't use most representation  aspects on a type derived from a generic formal type.

I understand. But with this statement:
   type Modele is delta <>  with SMALL => MODELE'DELTA;
I intend to pass a contract, so that only types whose Small is set the same as the Delta will be accepted as valid parameters. I SUPPOSED it works like this... I suppose now I was wrong ?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to force the Small aspect of a new type derived from the generic formal type ?
  2018-01-25  3:30 ` Randy Brukardt
  2018-01-25 12:54   ` Mehdi Saada
@ 2018-01-25 18:35   ` G. B.
  2018-01-26  4:42     ` Randy Brukardt
  1 sibling, 1 reply; 7+ messages in thread
From: G. B. @ 2018-01-25 18:35 UTC (permalink / raw)


Randy Brukardt <randy@rrsoftware.com> wrote:
> 
> ...; you can't use most representation 
> aspects on a type derived from a generic formal type.
> 
> Even if you were not in a generic unit, you can't usually put representation 
> aspects on a derived type (they usually have to match the original type). 

The “usually” calls attention to types derived from others
precisely to make their objects have a representation
that differs from those of the original type. (The case 
when a type conversion changes the representation.)
Plausibly, this feature does not blend with types being generic
in any sense.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to force the Small aspect of a new type derived from the generic formal type ?
  2018-01-25 12:54   ` Mehdi Saada
@ 2018-01-26  4:38     ` Randy Brukardt
  2018-01-26 11:13     ` Alejandro R. Mosteo
  1 sibling, 0 replies; 7+ messages in thread
From: Randy Brukardt @ 2018-01-26  4:38 UTC (permalink / raw)


"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:cb2eaa5d-f40d-4c35-8df4-b1e04d8d5a4b@googlegroups.com...
>> Either the teacher is asking for the impossible
>
> Actually the teacher isn't asking to do that: he asked at some point to 
> make it generic, at and at another, to force the Small. I assumed we could 
> do both.

You have to force the Small outside of the generic (on the actual type that 
is used to instantiate).

>>> you can't use most representation  aspects on a type derived from a 
>>> generic formal type.
>
> I understand. But with this statement:
>   type Modele is delta <>  with SMALL => MODELE'DELTA;
> I intend to pass a contract, so that only types whose Small is set the 
> same as the
> Delta will be accepted as valid parameters. I SUPPOSED it works like 
> this... I
> suppose now I was wrong ?

Most aspects can't be used on formal type because they would create an 
implicit contract that would require lots of rules to define. You in fact 
are trying to do exactly what we thought wasn't important enough to support.

In this case, you probably should just use an Assertion to make the check, 
that's not quite as good because it isn't a compile-time error (although you 
might get a warning from some compilers).

                                        Randy.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to force the Small aspect of a new type derived from the generic formal type ?
  2018-01-25 18:35   ` G. B.
@ 2018-01-26  4:42     ` Randy Brukardt
  0 siblings, 0 replies; 7+ messages in thread
From: Randy Brukardt @ 2018-01-26  4:42 UTC (permalink / raw)



"G. B." <nonlegitur@nmhp.invalid> wrote in message 
news:p4d81o$ds4$1@dont-email.me...
> Randy Brukardt <randy@rrsoftware.com> wrote:
>>
>> ...; you can't use most representation
>> aspects on a type derived from a generic formal type.
>>
>> Even if you were not in a generic unit, you can't usually put 
>> representation
>> aspects on a derived type (they usually have to match the original type).
>
> The "usually" calls attention to types derived from others
> precisely to make their objects have a representation
> that differs from those of the original type. (The case
> when a type conversion changes the representation.)
> Plausibly, this feature does not blend with types being generic
> in any sense.

Right, and that feature is only available for types that have no primitive 
operations. So it's not available for anything defined as an abstract data 
type or any form of object-oriented design. Thus isn't pretty limited in its 
value.

(It turns out that there is a bug in the rules that allows these rep. 
changing aspects in some cases where they are not supposed to be -- and it 
also turns out that users have been using this loophole. Killing the 
user-defined subprogram part of 13.1(10/4) is one of the things I've been 
(unsuccessfully) lobbying for for years.)

                           Randy. 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to force the Small aspect of a new type derived from the generic formal type ?
  2018-01-25 12:54   ` Mehdi Saada
  2018-01-26  4:38     ` Randy Brukardt
@ 2018-01-26 11:13     ` Alejandro R. Mosteo
  1 sibling, 0 replies; 7+ messages in thread
From: Alejandro R. Mosteo @ 2018-01-26 11:13 UTC (permalink / raw)


On 25/01/18 13:54, Mehdi Saada wrote:
>> Either the teacher is asking for the impossible
> 
> Actually the teacher isn't asking to do that: he asked at some point to make it generic, at and at another, to force the Small. I assumed we could do both.
> 
>> you can't use most representation  aspects on a type derived from a generic formal type.
> 
> I understand. But with this statement:
>     type Modele is delta <>  with SMALL => MODELE'DELTA;
> I intend to pass a contract, so that only types whose Small is set the same as the Delta will be accepted as valid parameters. I SUPPOSED it works like this... I suppose now I was wrong ?
> 

Unfortunately aspects+generics (or, in general <advanced 
feature>+generics) is one of the points where Ada orthogonality breaks 
down. In exchange you get sane generics, when compared to macro templates.

I'm saying this in a practical, user-experience sense, not as a language 
lawyer (which I'm not).

You can somewhat mitigate this with generic package formals, or with the 
"type T is new Base with private" kind of formals.

Even after many years of using Ada, I find the table in the following 
link a lifesaver from time to time:

https://en.wikibooks.org/wiki/Ada_Programming/Generics#Generic_formal_types

Incidentally, I wonder what good Ada cheatsheets are out there.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-01-26 11:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-24 19:16 how to force the Small aspect of a new type derived from the generic formal type ? Mehdi Saada
2018-01-25  3:30 ` Randy Brukardt
2018-01-25 12:54   ` Mehdi Saada
2018-01-26  4:38     ` Randy Brukardt
2018-01-26 11:13     ` Alejandro R. Mosteo
2018-01-25 18:35   ` G. B.
2018-01-26  4:42     ` Randy Brukardt

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