comp.lang.ada
 help / color / mirror / Atom feed
* Adding a "Project Types" layer to a project
@ 1996-05-01  0:00 Chris Papademetrious
  1996-05-01  0:00 ` Robert A Duff
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Chris Papademetrious @ 1996-05-01  0:00 UTC (permalink / raw)



I'm beginning a large project, and I'd like to base the entire project off base types defined in a package, as an extra layer of indirection for which I can 
change the underlying functionality later.  The problem is, I'm having problems adding this level of indirection.  Keep in mind I know very little about Ada 95, 
save for what I'm picking up here on the newsgroups and such...

 Here's what I have so far.  Note that I want everything in the project to use ONLY the types defined in the package "types", which I can change to affect the 
entire project.  This is the result I get when I try to compile this testcase:

/home/chrispy/bot > gnatmake test
gcc -c test.adb
test.adb:20:20: invalid operand types for operator "+"
gnatmake: *** compilation failed.

 If I use the type from the package "vectors" directly, it works.  If I create a subtype in types, and then use that, it fails.  What am I missing?  Thanks in 
advance...

 - Chris


===== vectors.ads:
package VECTORS is
  type VECTOR is array(integer range<>) of float ;

  function "+" (A : VECTOR; B : VECTOR) return VECTOR ; -- sum of vector
end VECTORS;

===== vectors.adb:
package body VECTORS is
  function "+" (A : VECTOR; B : VECTOR) return VECTOR is
    C : VECTOR(A'first..A'last) ;
  begin
    if A'first /= B'first or A'last /= B'last then
      raise INCOMPARABLE_DIMENSION;
    end if ;
    for I in A'range loop
      C(I) := A(I)+B(I) ;
    end loop ;
    return C ;
  end "+";
end VECTORS;

===== types.ads:
with Vectors;

package TYPES is
  subtype Distance is FLOAT;
  subtype Vector is Vectors.VECTOR;
end TYPES;


===== test.adb:
with Text_IO, Ada.Float_Text_IO, Ada.Integer_Text_IO;
with Types;

use Text_IO, Ada.Float_Text_IO, Ada.Integer_Text_IO;
use Types;

procedure test is

distance1: Distance := 2.0;
distance2: Distance := 3.0;
point1: Vector := (1.1, 2.2);
point2: Vector := (3.3, 4.4);

begin
  distance1 := distance1 + distance2;
  point1 := point1 + point2;
end;




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

end of thread, other threads:[~1996-05-06  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-01  0:00 Adding a "Project Types" layer to a project Chris Papademetrious
1996-05-01  0:00 ` Robert A Duff
1996-05-01  0:00 ` John English
1996-05-02  0:00 ` Chad Bremmon
1996-05-06  0:00   ` Chris Papademetrious

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