comp.lang.ada
 help / color / mirror / Atom feed
* Defining types in private packages for use in parent spec
@ 2003-08-27  7:51 Lutz Donnerhacke
  2003-08-27  8:56 ` Dmitry A. Kazakov
  2003-08-29 17:02 ` Stephen Leake
  0 siblings, 2 replies; 4+ messages in thread
From: Lutz Donnerhacke @ 2003-08-27  7:51 UTC (permalink / raw)


How to solve the following problem? It's necessary to define the type Base
in the implementation defined private subpackage, because it varies on
various implementations.

------------------------------------------------------------------------
package Bigints is
   type Bigint is limited private;
private
   type Base_Array;
   type Base_Access is access Base_Array;
   type Bigint is limited record
      data : Base_Access;
   end record;
end Bigints;

with System;
private package Bigints.Implementation is
   type Base is mod System.Max_Binary_Modulus;
   procedure Demo(a : in out Bigint);
end Bigints.Implementation;

with Bigints.Implementation;
package body Bigints is
   subtype Base is Implementation.Base;
   type Base_Array is array(Positive range <>) of Base;
end Bigints;

package body Bigints.Implementation is
   procedure Demo(a : in out Bigint) is
   begin
      for i in a.data'Range loop
         null;
      end loop;
   end Demo;
end Bigints.Implementation;
------------------------------------------------------------------------

gcc -c bigints.adb
gcc -c bigints-implementation.adb
bigints-implementation.adb:5:17: prefix for "Range" attribute must be array
gnatmake: "bigints-implementation.adb" compilation error



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

* Re: Defining types in private packages for use in parent spec
  2003-08-27  7:51 Defining types in private packages for use in parent spec Lutz Donnerhacke
@ 2003-08-27  8:56 ` Dmitry A. Kazakov
  2003-08-27  9:03   ` Lutz Donnerhacke
  2003-08-29 17:02 ` Stephen Leake
  1 sibling, 1 reply; 4+ messages in thread
From: Dmitry A. Kazakov @ 2003-08-27  8:56 UTC (permalink / raw)


On Wed, 27 Aug 2003 07:51:02 +0000 (UTC), Lutz Donnerhacke
<lutz@iks-jena.de> wrote:

>How to solve the following problem? It's necessary to define the type Base
>in the implementation defined private subpackage, because it varies on
>various implementations.

The first design question is when implementations should be selected?
At compile time or possibly at run time? For the latter case you have
only two options: tagged types vs. discriminated types (with a variant
part or not). Otherwise there is a third opton the generics. To
summarize, the ways you could come to different implementations of a
polymorphic object:

1. Tagged types: tag --- dispatch ---> implementation
2. Discriminated types: discriminant(s) --- case ----> implementation
3. "Generic" types: parameter(s) --- instantiation ---> implementation

Private vs. public, child vs. unrelated package is the second and less
important question. Usually when you solve the first and define the
public interface of your objects, you will have little choice to
decide.

---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



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

* Re: Defining types in private packages for use in parent spec
  2003-08-27  8:56 ` Dmitry A. Kazakov
@ 2003-08-27  9:03   ` Lutz Donnerhacke
  0 siblings, 0 replies; 4+ messages in thread
From: Lutz Donnerhacke @ 2003-08-27  9:03 UTC (permalink / raw)


* Dmitry A Kazakov wrote:
> 1. Tagged types: tag --- dispatch ---> implementation
> 2. Discriminated types: discriminant(s) --- case ----> implementation

Too much overhead. The type have to be as compact as possible to avoid bloat.

> 3. "Generic" types: parameter(s) --- instantiation ---> implementation

Good suggestion. Thank you.




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

* Re: Defining types in private packages for use in parent spec
  2003-08-27  7:51 Defining types in private packages for use in parent spec Lutz Donnerhacke
  2003-08-27  8:56 ` Dmitry A. Kazakov
@ 2003-08-29 17:02 ` Stephen Leake
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Leake @ 2003-08-29 17:02 UTC (permalink / raw)


Lutz Donnerhacke <lutz@iks-jena.de> writes:

> How to solve the following problem? It's necessary to define the type Base
> in the implementation defined private subpackage, because it varies on
> various implementations.
> 
> ------------------------------------------------------------------------
> package Bigints is
>    type Bigint is limited private;
> private
>    type Base_Array;
>    type Base_Access is access Base_Array;
>    type Bigint is limited record
>       data : Base_Access;
>    end record;
> end Bigints;

One option is to add an "iterator" subprogram here, that
Bigints.Implementation.Demo can use to walk thru Base_Array.

> with System;
> private package Bigints.Implementation is
>    type Base is mod System.Max_Binary_Modulus;
>    procedure Demo(a : in out Bigint);
> end Bigints.Implementation;

Another option is to move Demo to Bigints (where it can see the array
type). 


-- 
-- Stephe



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

end of thread, other threads:[~2003-08-29 17:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-27  7:51 Defining types in private packages for use in parent spec Lutz Donnerhacke
2003-08-27  8:56 ` Dmitry A. Kazakov
2003-08-27  9:03   ` Lutz Donnerhacke
2003-08-29 17:02 ` Stephen Leake

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