comp.lang.ada
 help / color / mirror / Atom feed
* GENERIC SPEC TYPE ERROR
@ 2005-11-16 10:43 rashmi
  2005-11-16 11:23 ` Georg Bauhaus
  2005-11-16 11:33 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 4+ messages in thread
From: rashmi @ 2005-11-16 10:43 UTC (permalink / raw)


Hi

I have created a generic specification for doing a vector operation
called PROC_Kronecker as shown below.
------------------------------------------------------------------------------------------------------------------------------------
File: PROC_KRONECKER.ads
------------------------------------------------------------------------------------------------------------------------------------


generic
	type PV_Vtyp is Private ;
	type VC_Rnge is range <>;
	type VC_Type is array(VC_Rnge) of PV_Vtyp;
	with function "*"(PV_Left,PV_Rigt : in PV_Vtyp) return PV_Vtyp;
	procedure PROC_Kronecker(VC_Left , VC_Rigt   : in VC_Type;VC_Resl:out
VC_Type);

------------------------------------------------------------------------------------------------------------------------------------

The associated body PROC_KRONECKER.adb works correctly for the above
spec. But when I tried to change the VC_Rnge and VC_Type to the
following:

                type VC_Rnge is Positive;
	type VC_Type is array(1..VC_Rnge) of PV_Vtyp;

then GNAT did not compile saying "Expecting generic type definition
here" where I have declared "Positive". Can someone clarify precisely
why the above cannot be valid ?




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

* Re: GENERIC SPEC TYPE ERROR
  2005-11-16 10:43 GENERIC SPEC TYPE ERROR rashmi
@ 2005-11-16 11:23 ` Georg Bauhaus
  2005-11-16 11:33 ` Dmitry A. Kazakov
  1 sibling, 0 replies; 4+ messages in thread
From: Georg Bauhaus @ 2005-11-16 11:23 UTC (permalink / raw)


rashmi wrote:

>                 type VC_Rnge is Positive;
> 	type VC_Type is array(1..VC_Rnge) of PV_Vtyp;

in "array (1 .. 100)", two values, 1, and 100, specify
the bounds of the array. In "array (1 .. Positive)"
the identifier "Positive" does not denote a value, but a type.

If you want VC_Rnge to be a value, then declare

   VC_Rnge: Positive;



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

* Re: GENERIC SPEC TYPE ERROR
  2005-11-16 10:43 GENERIC SPEC TYPE ERROR rashmi
  2005-11-16 11:23 ` Georg Bauhaus
@ 2005-11-16 11:33 ` Dmitry A. Kazakov
  2005-11-18 11:58   ` rashmi
  1 sibling, 1 reply; 4+ messages in thread
From: Dmitry A. Kazakov @ 2005-11-16 11:33 UTC (permalink / raw)


On 16 Nov 2005 02:43:34 -0800, rashmi wrote:

> I have created a generic specification for doing a vector operation
> called PROC_Kronecker as shown below.
> ------------------------------------------------------------------------------------------------------------------------------------
> File: PROC_KRONECKER.ads
> ------------------------------------------------------------------------------------------------------------------------------------
> 
> 
> generic
> 	type PV_Vtyp is Private ;
> 	type VC_Rnge is range <>;
> 	type VC_Type is array(VC_Rnge) of PV_Vtyp;
> 	with function "*"(PV_Left,PV_Rigt : in PV_Vtyp) return PV_Vtyp;
> 	procedure PROC_Kronecker(VC_Left , VC_Rigt   : in VC_Type;VC_Resl:out
> VC_Type);
> 
> ------------------------------------------------------------------------------------------------------------------------------------
> 
> The associated body PROC_KRONECKER.adb works correctly for the above
> spec. But when I tried to change the VC_Rnge and VC_Type to the
> following:
> 
>                 type VC_Rnge is Positive;
> 	type VC_Type is array(1..VC_Rnge) of PV_Vtyp;
> 
> then GNAT did not compile saying "Expecting generic type definition
> here" where I have declared "Positive". Can someone clarify precisely
> why the above cannot be valid ?

type VC_Rnge is Positive <-- here a generic type specification is expected.
You have "Positive" instead, which is not generic, but a concrete type.
Generic types are sets of types. You can consider them as types of types,
which values are normal types.

The following line is also wrong. VC_Rnge is a type, but 1..VC_Rnge assumes
a value. Probably

generic
   type Element_Type is Private ;
   type Index_Type is range <>;
   type Array_Type is array (Index_Type range <>) of Element_Type;
   with function "*" (Left, Right : Element_Type)
      return Element_Type is <>;
function Kronecker (Left, Right : Array_Type) return Element_Type;

is what you need. However it is not clear what are you trying to achieve.
What should be variable in your generic package 1) the types or 2)
constraints on types or some mixture of both? 

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



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

* Re: GENERIC SPEC TYPE ERROR
  2005-11-16 11:33 ` Dmitry A. Kazakov
@ 2005-11-18 11:58   ` rashmi
  0 siblings, 0 replies; 4+ messages in thread
From: rashmi @ 2005-11-18 11:58 UTC (permalink / raw)


Dear Dmitry A. Kazakov

Thanks for your suggestions.I found them helpful.




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

end of thread, other threads:[~2005-11-18 11:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-16 10:43 GENERIC SPEC TYPE ERROR rashmi
2005-11-16 11:23 ` Georg Bauhaus
2005-11-16 11:33 ` Dmitry A. Kazakov
2005-11-18 11:58   ` rashmi

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