comp.lang.ada
 help / color / mirror / Atom feed
* numbers as 'generics' parameters
@ 2008-05-16 17:26 jhc0033
  2008-05-16 17:55 ` Adam Beneschan
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: jhc0033 @ 2008-05-16 17:26 UTC (permalink / raw)


C++ allows integers as template parameters, so, for example I can
define a vector of size N, and verify at compile time that, say, I
don't try the inner product of a 2D (N=2) and 3D (N=3) vectors. On the
other hand, I don't have to write separate versions of my code for
various vector sizes.

As far as I can tell, Ada does not allow anything but types as
generics parameters, so what would be the approach to use with it?

a. code duplication
b. keep vector size at runtime (and check)



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

* Re: numbers as 'generics' parameters
  2008-05-16 17:26 numbers as 'generics' parameters jhc0033
@ 2008-05-16 17:55 ` Adam Beneschan
  2008-05-16 19:12   ` John B. Matthews
  2008-05-16 18:34 ` jimmaureenrogers
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 18+ messages in thread
From: Adam Beneschan @ 2008-05-16 17:55 UTC (permalink / raw)


On May 16, 10:26 am, "jhc0...@gmail.com" <jhc0...@gmail.com> wrote:
> C++ allows integers as template parameters, so, for example I can
> define a vector of size N, and verify at compile time that, say, I
> don't try the inner product of a 2D (N=2) and 3D (N=3) vectors. On the
> other hand, I don't have to write separate versions of my code for
> various vector sizes.
>
> As far as I can tell, Ada does not allow anything but types as
> generics parameters, so what would be the approach to use with it?

My recommended approach would be to read what the Ada reference manual
says about generics.  Sorry to be so harsh, but your above assertion
("does not allow anything but types") is so far off base that it
appears you've just gotten hold of some bad information, and that
needs to be fixed first.

                                     -- Adam






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

* Re: numbers as 'generics' parameters
  2008-05-16 17:26 numbers as 'generics' parameters jhc0033
  2008-05-16 17:55 ` Adam Beneschan
@ 2008-05-16 18:34 ` jimmaureenrogers
  2008-05-16 18:57 ` Gautier
  2008-05-16 20:22 ` Jeffrey R. Carter
  3 siblings, 0 replies; 18+ messages in thread
From: jimmaureenrogers @ 2008-05-16 18:34 UTC (permalink / raw)


Ada does not require the definition of a generic for your example.
Ada provides the ability to define unconstrained array types.

For example, the following package specification defines a vector
type and some operations on that type.

package Vectors is
   subtype Index_Type is Integer range 1..Integer'Last;
   type Vector is array(Index_Type range <>) of Float;
   function "*"(Left : Float; Right : Vector) return Vector;
   function "*"(Left : Vector; Right : Float) return Vector;
   function "*"(Left, Right : Vector) return Vector;
   function "-"(Left : Float; Right : Vector) return Vector;
   function "-"(Left : Vector; Right : Float) return Vector;
   function "-"(Left, Right : Vector) return Vector;
   function "+"(Left : Float; Right : Vector) return Vector;
   function "+"(Left : Vector; Right : Float) return Vector;
   function "+"(Left, Right : Vector) return Vector;
   function "/"(Left : Vector; Right : Float) return Vector;
end Vectors;

Ada provides both compile-time and run-time checks on the
array bounds for type Vector, even though an instance of
Vector can be of any size up to Integer'Last.

Your questions about Ada indicate very little exposure to Ada.
I concur with Adam's recommendation above. Please read up on
Ada. You will find the language to be very usable and very
efficient.

Jim Rogers



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

* Re: numbers as 'generics' parameters
  2008-05-16 17:26 numbers as 'generics' parameters jhc0033
  2008-05-16 17:55 ` Adam Beneschan
  2008-05-16 18:34 ` jimmaureenrogers
@ 2008-05-16 18:57 ` Gautier
  2008-05-16 20:52   ` Maciej Sobczak
  2008-05-16 20:22 ` Jeffrey R. Carter
  3 siblings, 1 reply; 18+ messages in thread
From: Gautier @ 2008-05-16 18:57 UTC (permalink / raw)


jhc0033@gmail.com:

> As far as I can tell, Ada does not allow anything but types as
> generics parameters, so what would be the approach to use with it?

Uh ?..

generic
   N: Integer;
package Fixed_size_vectors is
   Vector: array(1..N) of Float;
end;

__________________________________________________________________
Gautier's Ada programming -- http://sourceforge.net/users/gdemont/

NB: For a direct answer, e-mail address on the Web site!



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

* Re: numbers as 'generics' parameters
  2008-05-16 17:55 ` Adam Beneschan
@ 2008-05-16 19:12   ` John B. Matthews
  0 siblings, 0 replies; 18+ messages in thread
From: John B. Matthews @ 2008-05-16 19:12 UTC (permalink / raw)


In article 
<514f8014-235d-4f52-aae1-c5b862dd6594@y22g2000prd.googlegroups.com>,
 Adam Beneschan <adam@irvine.com> wrote:

> On May 16, 10:26 am, "jhc0...@gmail.com" <jhc0...@gmail.com> wrote:
> > C++ allows integers as template parameters, so, for example I can
> > define a vector of size N, and verify at compile time that, say, I
> > don't try the inner product of a 2D (N=2) and 3D (N=3) vectors. On the
> > other hand, I don't have to write separate versions of my code for
> > various vector sizes.
> >
> > As far as I can tell, Ada does not allow anything but types as
> > generics parameters, so what would be the approach to use with it?
> 
> My recommended approach would be to read what the Ada reference manual
> says about generics.  Sorry to be so harsh, but your above assertion
> ("does not allow anything but types") is so far off base that it
> appears you've just gotten hold of some bad information, and that
> needs to be fixed first.
> 
>                                      -- Adam

Good places to start:

<http://www.adaic.org/standards/95rat/RAThtml/rat95-contents.html>
<http://www.adaic.com/standards/05rat/html/Rat-TOC.html>

John
-- 
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews



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

* Re: numbers as 'generics' parameters
  2008-05-16 17:26 numbers as 'generics' parameters jhc0033
                   ` (2 preceding siblings ...)
  2008-05-16 18:57 ` Gautier
@ 2008-05-16 20:22 ` Jeffrey R. Carter
  2008-05-21 15:32   ` Robert A Duff
  3 siblings, 1 reply; 18+ messages in thread
From: Jeffrey R. Carter @ 2008-05-16 20:22 UTC (permalink / raw)


jhc0033@gmail.com wrote:
> 
> As far as I can tell, Ada does not allow anything but types as
> generics parameters, so what would be the approach to use with it?

ARM 12.1 (http://www.adaic.org/standards/05rm/html/RM-12-1.html) lists 4 kinds 
of generic formal parameters, only one of which is a type. So you clearly 
haven't done much investigation of Ada.

In addition to a generic formal parameter, you can have various subtypes of an 
unconstrained array type, or a discriminated record type with an array component 
constrained by the discriminant, to achieve similar things.

-- 
Jeff Carter
"You me on the head hitted."
Never Give a Sucker an Even Break
108



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

* Re: numbers as 'generics' parameters
  2008-05-16 18:57 ` Gautier
@ 2008-05-16 20:52   ` Maciej Sobczak
  2008-05-16 23:09     ` Peter C. Chapin
  2008-05-17  7:47     ` Dmitry A. Kazakov
  0 siblings, 2 replies; 18+ messages in thread
From: Maciej Sobczak @ 2008-05-16 20:52 UTC (permalink / raw)


On 16 Maj, 20:57, Gautier <gaut...@fakeaddress.nil> wrote:

> generic
>    N: Integer;
> package Fixed_size_vectors is
>    Vector: array(1..N) of Float;

I guess:
     type Vector is array (1..N) of Float;

> end;

How to write an operation that ensures *at compile time* that its two
parameters are Fixed_size_vectors of equal N?
Declare it in a child package? Is there any other option?

Similar question can be asked for (un)constrained and discriminated
types. What are the options for such an operation?

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com



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

* Re: numbers as 'generics' parameters
  2008-05-16 20:52   ` Maciej Sobczak
@ 2008-05-16 23:09     ` Peter C. Chapin
  2008-05-17  7:47     ` Dmitry A. Kazakov
  1 sibling, 0 replies; 18+ messages in thread
From: Peter C. Chapin @ 2008-05-16 23:09 UTC (permalink / raw)


Maciej Sobczak wrote:

> On 16 Maj, 20:57, Gautier <gaut...@fakeaddress.nil> wrote:
> 
>> generic
>>    N: Integer;
>> package Fixed_size_vectors is
>>    Vector: array(1..N) of Float;
> 
> I guess:
>      type Vector is array (1..N) of Float;
> 
>> end;
> 
> How to write an operation that ensures *at compile time* that its two
> parameters are Fixed_size_vectors of equal N?

I may not understand the question, but isn't this trivial?

procedure Check is
    package Short_Vectors is new Fixed_Size_Vectors(N => 3);
    package Long_Vectors is new Fixed_Size_Vectors(N => 6);

    V1     : Short_Vectors.Vector;
    V2, V3 : Long_Vectors.Vector;
begin
    V3 := V1 + V2;
end Check;

Assuming an appropriate overload for "+" this produces a compile time 
error for me.

Peter



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

* Re: numbers as 'generics' parameters
  2008-05-16 20:52   ` Maciej Sobczak
  2008-05-16 23:09     ` Peter C. Chapin
@ 2008-05-17  7:47     ` Dmitry A. Kazakov
  2008-05-17 16:29       ` Maciej Sobczak
  1 sibling, 1 reply; 18+ messages in thread
From: Dmitry A. Kazakov @ 2008-05-17  7:47 UTC (permalink / raw)


On Fri, 16 May 2008 13:52:23 -0700 (PDT), Maciej Sobczak wrote:

> On 16 Maj, 20:57, Gautier <gaut...@fakeaddress.nil> wrote:
> 
>> generic
>>    N: Integer;
>> package Fixed_size_vectors is
>>    Vector: array(1..N) of Float;
> 
> I guess:
>      type Vector is array (1..N) of Float;
> 
>> end;
> 
> How to write an operation that ensures *at compile time* that its two
> parameters are Fixed_size_vectors of equal N?
> Declare it in a child package? Is there any other option?

The first step is a bit tedious, but it is advisable to "rename" all formal
generic parameters within the package specification. [I don't know why
aren't they visible. That was a language design decision].

Anyway, here you go:

   generic
      N : Integer;
   package Fixed_Size_Vector is
      Size : Integer renames N;
      type Vector is array (1..N) of Float;
   end Fixed_Size_Vector;
   
   package V1 is new Fixed_Size_Vector (25);
   package V2 is new Fixed_Size_Vector (V1.Size);

> Similar question can be asked for (un)constrained and discriminated
> types. What are the options for such an operation?

You do it declaring a subtype, that constraints the discriminant or bounds.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: numbers as 'generics' parameters
  2008-05-17  7:47     ` Dmitry A. Kazakov
@ 2008-05-17 16:29       ` Maciej Sobczak
  2008-05-17 17:34         ` Dmitry A. Kazakov
  0 siblings, 1 reply; 18+ messages in thread
From: Maciej Sobczak @ 2008-05-17 16:29 UTC (permalink / raw)


On 17 Maj, 09:47, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:

> > Similar question can be asked for (un)constrained and discriminated
> > types. What are the options for such an operation?
>
> You do it declaring a subtype, that constraints the discriminant or bounds.

I see - however, this requires the declaration of a constrained
subtype.
What about this:

procedure P (X : in String; Y : in String);

This procedure accepts two strings of any length - and they can have
different lengths. What about limiting this and allowing the user to
call P only with two strings of the same length?
Declaring a constrained subtype would fix the length to the one used
in type declaration. Is it possible to define P in a way that allows
strings of any length, but equal?

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com



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

* Re: numbers as 'generics' parameters
  2008-05-17 16:29       ` Maciej Sobczak
@ 2008-05-17 17:34         ` Dmitry A. Kazakov
  2008-05-18 13:58           ` Maciej Sobczak
  0 siblings, 1 reply; 18+ messages in thread
From: Dmitry A. Kazakov @ 2008-05-17 17:34 UTC (permalink / raw)


On Sat, 17 May 2008 09:29:34 -0700 (PDT), Maciej Sobczak wrote:

> On 17 Maj, 09:47, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
> 
> What about this:
> 
> procedure P (X : in String; Y : in String);
> 
> This procedure accepts two strings of any length - and they can have
> different lengths. What about limiting this and allowing the user to
> call P only with two strings of the same length?

> Declaring a constrained subtype would fix the length to the one used
> in type declaration. Is it possible to define P in a way that allows
> strings of any length, but equal?

How are going to check string length statically?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: numbers as 'generics' parameters
  2008-05-17 17:34         ` Dmitry A. Kazakov
@ 2008-05-18 13:58           ` Maciej Sobczak
  2008-05-18 14:52             ` Dmitry A. Kazakov
  2008-05-19  5:16             ` Ivan Levashew
  0 siblings, 2 replies; 18+ messages in thread
From: Maciej Sobczak @ 2008-05-18 13:58 UTC (permalink / raw)


On 17 Maj, 19:34, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:

> How are going to check string length statically?

That's what I'm asking. OP asked about numbers in generics, motivating
his question with compile-time checks. Surely he comes from C++ and he
was later flooded with answers that focused on numbers, generics and
alternatives, but the "compile-time" part of the discussion was
immediately lost.

I can bet that OP was asking about this:

template <size_t N>
void foo(const fixed_size_string<N> & s1,
         const fixed_size_string<N> & s2)
{
    // some processing here
}

fixed_size_string<3> s = "Ada";
fixed_size_string<3> t = "C++";
fixed_size_string<4> u = "Java"

foo(s, t); // OK, s and t have statically equal lengths
foo(s, u); // compile-time error *here*

Yes, Ada allows to use numbers in types - in various ways.
But the OP's question is still not directly addressed.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com



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

* Re: numbers as 'generics' parameters
  2008-05-18 13:58           ` Maciej Sobczak
@ 2008-05-18 14:52             ` Dmitry A. Kazakov
  2008-05-18 20:37               ` Maciej Sobczak
  2008-05-19  5:16             ` Ivan Levashew
  1 sibling, 1 reply; 18+ messages in thread
From: Dmitry A. Kazakov @ 2008-05-18 14:52 UTC (permalink / raw)


On Sun, 18 May 2008 06:58:03 -0700 (PDT), Maciej Sobczak wrote:

> On 17 Maj, 19:34, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
> 
>> How are going to check string length statically?
> 
> That's what I'm asking. OP asked about numbers in generics, motivating
> his question with compile-time checks. Surely he comes from C++ and he
> was later flooded with answers that focused on numbers, generics and
> alternatives, but the "compile-time" part of the discussion was
> immediately lost.
>
> I can bet that OP was asking about this:
> 
> template <size_t N>
> void foo(const fixed_size_string<N> & s1,
>          const fixed_size_string<N> & s2)
> {
>     // some processing here
> }
> 
> fixed_size_string<3> s = "Ada";
> fixed_size_string<3> t = "C++";
> fixed_size_string<4> u = "Java"
> 
> foo(s, t); // OK, s and t have statically equal lengths
> foo(s, u); // compile-time error *here*

generic
   N : Natural;
package Strings_Nobody_Ever_Needed is
   type Pascal_String is new String (1..N);
   procedure Foo (L, R : Pascal_String);
end Strings_Nobody_Ever_Needed;

In your example string length is static. So it could be enforced
statically. When you asked for a procedure which enforces same constraint
on two arguments, that is a completely different thing, from what your
example presents. You do not have *one* procedure there.

If you replaced the type declaration in Strings_Nobody_Ever_Needed to

   subtype Pascal_String is String (1..N);

you would start to see what's wrong with all this... (:-))

Talking about strings, they are allowed to have statically unknown length,
so a request to check it statically is meaningless and wrong:

declare
   X : String (1..40);
begin
   X := Y;  -- This *shall* compile and legal no matter of Y'Length
exception
   when Constraint_Error =>
      if Y'Length > X'Length then
         X := Y (Y'First..Y'First + X'Length - 1);
      else
         X (X'First..X'First + Y'Length - 1) := Y;
      end if;
end;

> Yes, Ada allows to use numbers in types - in various ways.
> But the OP's question is still not directly addressed.

His question was answered. It is possible to have formal objects in
generics. Each instantiation produces new instance of everything inside, so
it is statically different from any other instance, which is a drawback,
not an advantage. If instances need to bound over a parameter, that is
possible to do as I have showed in my earlier post. Differently to C++ it
has to be done explicitly because matching the instances is named in Ada
(by structure in C++), which is an advantage, not a drawback...

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: numbers as 'generics' parameters
  2008-05-18 14:52             ` Dmitry A. Kazakov
@ 2008-05-18 20:37               ` Maciej Sobczak
  2008-05-19  9:02                 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 18+ messages in thread
From: Maciej Sobczak @ 2008-05-18 20:37 UTC (permalink / raw)


On 18 Maj, 16:52, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:

> generic
>    N : Natural;
> package Strings_Nobody_Ever_Needed is
>    type Pascal_String is new String (1..N);
>    procedure Foo (L, R : Pascal_String);
> end Strings_Nobody_Ever_Needed;

No. The package is already written and no code can be added.
A child package would do, perhaps?

Note also that the constraint to have equal strings is only an example
and probably does not show the full problem.
I might have written my code like this instead:

template <size_t N>
void foo(const fixed_size_string<N> & s1,
         const fixed_size_string<2 * N> & s2);

and it would ensure *at compile time* that the second string is twice
as long as the first one. It should be obvious now that such a
constraint can be anything that is computable (at compile time).
What about this?

(again: the package in question is read only)

> If you replaced the type declaration in Strings_Nobody_Ever_Needed to
>
>    subtype Pascal_String is String (1..N);
>
> you would start to see what's wrong with all this... (:-))

No, I don't follow. Could you please explain?

> Talking about strings, they are allowed to have statically unknown length

Yes - the string was only a vehicle to show the problem. It might be a
matrix of size N or just about anything else.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com



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

* Re: numbers as 'generics' parameters
  2008-05-18 13:58           ` Maciej Sobczak
  2008-05-18 14:52             ` Dmitry A. Kazakov
@ 2008-05-19  5:16             ` Ivan Levashew
  2008-05-19  8:26               ` Maciej Sobczak
  1 sibling, 1 reply; 18+ messages in thread
From: Ivan Levashew @ 2008-05-19  5:16 UTC (permalink / raw)


Maciej Sobczak пишет:
> template <size_t N>
> void foo(const fixed_size_string<N> & s1,
>          const fixed_size_string<N> & s2)

AFAIK this will prevent N from being unknown at compile-time. Or anyway 
I don't know how will C++ handle undefined N. AFAIK C++, there could be 
"foo <3> (const fixed_size_string<3> &, const fixed_size_string<3> &)",
"foo <4> (const fixed_size_string<4> &, const fixed_size_string<4> &)" 
mangled names. I'm not sure if C++ is able to convert dynamic template 
parameters to subroutine parameters. This could be probably solved by 
replacing "size_t N" with "const size_t& N", but AFAIK it'll render the 
automatic being demonstrated here invalid since

fixed_size_string<3> s = "Ada";
fixed_size_string<3> t = "C++";

are likely to use different "size_t&" references, aren't they?

I think this particular case is a dead-end way of promoting either Ada 
over C++ or C++ over Ada.

-- 
If you want to get to the top, you have to start at the bottom



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

* Re: numbers as 'generics' parameters
  2008-05-19  5:16             ` Ivan Levashew
@ 2008-05-19  8:26               ` Maciej Sobczak
  0 siblings, 0 replies; 18+ messages in thread
From: Maciej Sobczak @ 2008-05-19  8:26 UTC (permalink / raw)


On 19 Maj, 07:16, Ivan Levashew <octag...@bluebottle.com> wrote:

> > template <size_t N>
> > void foo(const fixed_size_string<N> & s1,
> >          const fixed_size_string<N> & s2)
>
> AFAIK this will prevent N from being unknown at compile-time.

Yes.

> AFAIK C++, there could be
> "foo <3> (const fixed_size_string<3> &, const fixed_size_string<3> &)",
> "foo <4> (const fixed_size_string<4> &, const fixed_size_string<4> &)"
> mangled names.

Yes.

> I'm not sure if C++ is able to convert dynamic template
> parameters to subroutine parameters.

There are no dynamic template parameters in C++.
In other words, C++ templates and Ada generics solve overlapping, but
not equivalent problems.

> I think this particular case is a dead-end way of promoting either Ada
> over C++ or C++ over Ada.

I try not to do it. I can try, however, bring more light to the
problem raised by OP.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com



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

* Re: numbers as 'generics' parameters
  2008-05-18 20:37               ` Maciej Sobczak
@ 2008-05-19  9:02                 ` Dmitry A. Kazakov
  0 siblings, 0 replies; 18+ messages in thread
From: Dmitry A. Kazakov @ 2008-05-19  9:02 UTC (permalink / raw)


On Sun, 18 May 2008 13:37:47 -0700 (PDT), Maciej Sobczak wrote:

> On 18 Maj, 16:52, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
> 
> Note also that the constraint to have equal strings is only an example
> and probably does not show the full problem.

(The problem; I don't understand, BTW)

> I might have written my code like this instead:
> 
> template <size_t N>
> void foo(const fixed_size_string<N> & s1,
>          const fixed_size_string<2 * N> & s2);

Easily:

generic
   N : Natural;
package Silly_String is
   type Pascal_String is new String (1..N);
end Silly_String;

with Silly_String;
generic
   with package One_Silly is  new Silly_String (<>);
   with package Twice_As_Silly is
      new Silly_String (One_Silly.Pascal_String'Length * 2);
procedure Foo
          (  S1 : One_Silly.Pascal_String;
             S2 : Twice_As_Silly.Pascal_String
          );

>> If you replaced the type declaration in Strings_Nobody_Ever_Needed to
>>
>>    subtype Pascal_String is String (1..N);
>>
>> you would start to see what's wrong with all this... (:-))
> 
> No, I don't follow. Could you please explain?

This Pascal_String would clash when multiple instantiated. The constraint
in your examples is a part of the type. This is wrong. The constraint of
the subtype is a proper constraint. To violate it is *legal*, so in order
to check it statically you need other (finer) means.
 
>> Talking about strings, they are allowed to have statically unknown length
> 
> Yes - the string was only a vehicle to show the problem. It might be a
> matrix of size N or just about anything else.

Still, for a vast majority of them, it is wrong to have the constraint a
part of the type. This is a fundamental issue, why generics are not a
solution.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: numbers as 'generics' parameters
  2008-05-16 20:22 ` Jeffrey R. Carter
@ 2008-05-21 15:32   ` Robert A Duff
  0 siblings, 0 replies; 18+ messages in thread
From: Robert A Duff @ 2008-05-21 15:32 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org> writes:

> jhc0033@gmail.com wrote:
>> As far as I can tell, Ada does not allow anything but types as
>> generics parameters, so what would be the approach to use with it?
>
> ARM 12.1 (http://www.adaic.org/standards/05rm/html/RM-12-1.html) lists 4
> kinds of generic formal parameters, only one of which is a type. So you
> clearly haven't done much investigation of Ada.

I don't think it's a good idea to learn Ada from the RM.
Better to use a good textbook.  I like Barnes.

Anyway, it's not a sin to be ignorant of Ada.  And generic formal
objects are a pretty obscure and little-used feature -- MOST generic
formal parameters are indeed types, so it's easy to get the incorrect
impression that that's all there is.

Now that Ada 2005 supports downward closures, even generic formal
subprograms are (or should be) a little-used feature.

- Bob



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

end of thread, other threads:[~2008-05-21 15:32 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-16 17:26 numbers as 'generics' parameters jhc0033
2008-05-16 17:55 ` Adam Beneschan
2008-05-16 19:12   ` John B. Matthews
2008-05-16 18:34 ` jimmaureenrogers
2008-05-16 18:57 ` Gautier
2008-05-16 20:52   ` Maciej Sobczak
2008-05-16 23:09     ` Peter C. Chapin
2008-05-17  7:47     ` Dmitry A. Kazakov
2008-05-17 16:29       ` Maciej Sobczak
2008-05-17 17:34         ` Dmitry A. Kazakov
2008-05-18 13:58           ` Maciej Sobczak
2008-05-18 14:52             ` Dmitry A. Kazakov
2008-05-18 20:37               ` Maciej Sobczak
2008-05-19  9:02                 ` Dmitry A. Kazakov
2008-05-19  5:16             ` Ivan Levashew
2008-05-19  8:26               ` Maciej Sobczak
2008-05-16 20:22 ` Jeffrey R. Carter
2008-05-21 15:32   ` Robert A Duff

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