Ada 0y wish list: parameters of package parameters 
Author Message
 Ada 0y wish list: parameters of package parameters

My main wish about Ada-0Y is about the following.

I am used to defining what I call 'signature packages', generic
packages with in principle nothing inside, but suitable to
define future parameters.

    generic
        type Item_Type is private ;
        -- operations defining something like an algebraic structure
    package Some_Algebra is end ;

Example of use :

    generic
        with package Numbers is new Ring_Structure ( <> ) ;
    package Polynomials is
        ...
    end Polynomials ;

No problem at this point.

The problem appears when I add signatures for order structures,
and try to specify. The intent is :

    generic
        with package Structure_1 is new Algrbraic_Structure ( any parameters ) ;
        with package Structure_2 is new Order_Structure ( same type ,
anything else ) ;
    package Something is
        ...
    end Something ;

Ada-95 solutions are complex and not fully general.
A possible syntax could be :

        with package Structure_1 is new Algrbraic_Structure ( <> ) ;
        with package Structure_2 is new Order_Structure
                    ( Structure_1 . Item_Type , others => <> ) ;

Any suggestion or opinion ?

----------          ----------          ----------          ----------
Michel Gauthier / Laboratoire d'informatique
83, rue d'Isle / F-87000 Limoges
telephone +33 555 43 69 73
fax +33 555 43 69 77
----------          ----------          ----------          ----------
Nous n'etions pas dans la langueur,
nous ne sombrons pas dans l'allegresse.
----------          ----------          ----------          ----------



Mon, 04 Aug 2003 21:07:00 GMT  
 Ada 0y wish list: parameters of package parameters
stuff deleted...

Quote:
> Ada-95 solutions are complex and not fully general.
> A possible syntax could be :

>         with package Structure_1 is new Algrbraic_Structure ( <> ) ;
>         with package Structure_2 is new Order_Structure
>                     ( Structure_1 . Item_Type , others => <> ) ;

> Any suggestion or opinion ?

Yes! I had a simlar problem a while back.

I was working on numerical integration code, and wanted to bring
together three such signature packages.  One defined the domain of
integration, one defined the type of the result, one defined
the integrand function.  Of course, the generic should
specify that the integrand must return the same type

At the time I was new to Ada, and expected to be able to use your
syntax above - it seemed the "Ada way".  I contacted a (well known)
Ada expert, and was advised it couldn't be done how I wanted.

My solution was to add generic functions, which converted
between the types:

         with package Structure_1 is new Algrbraic_Structure ( <> ) ;
         with package Structure_2 is new Order_Structure     ( <> ) ;
         with function Convert (X : Structure_1 . Item_Type)
              return Structure_2.Item_Type;
         with function Convert (X : Structure_2 . Item_Type)
              return Structure_1.Item_Type;

This allows the package to use the two types interchangably,
provided that the Convert functions are called, if necessary.
You could use Unchecked_Conversion between the types, if you
believe them to be the same.

The alternative I could see in my case was to replace the package
generic parameters with all the contents of the specification that
were needed.  Every time a type occurs which need to be the same
in Structure_1 and Structure_2, you only have it once.
This is general (I think), but can be very verbose, and obscures
the abstraction.

I can't at this moment see any major implementation problem with Michel's
suggestion, but I'm not qualified to comment.

Maybe someone here should sumbit a proposal to address the problem.
--
Dr Adrian Wrigley



Wed, 06 Aug 2003 16:24:19 GMT  
 Ada 0y wish list: parameters of package parameters

Quote:
> <snip>

> My solution was to add generic functions, which converted
> between the types:

>          with package Structure_1 is new Algrbraic_Structure ( <> ) ;
>          with package Structure_2 is new Order_Structure     ( <> ) ;
>          with function Convert (X : Structure_1 . Item_Type)
>               return Structure_2.Item_Type;
>          with function Convert (X : Structure_2 . Item_Type)
>               return Structure_1.Item_Type;

> This allows the package to use the two types interchangably,
> provided that the Convert functions are called, if necessary.
> You could use Unchecked_Conversion between the types, if you
> believe them to be the same.

Better to use an inlined Copy function; the compiler will warn you if
something changes during maintenance.

Quote:
> The alternative I could see in my case was to replace the package
> generic parameters with all the contents of the specification that
> were needed. Every time a type occurs which need to be the same in
> Structure_1 and Structure_2, you only have it once. This is general
> (I think), but can be very verbose, and obscures the abstraction.

Perhaps Item_Type should be a generic parameter of both Structure_1
and Structure_2?

--
-- Stephe



Sun, 10 Aug 2003 02:28:31 GMT  
 Ada 0y wish list: parameters of package parameters
Just to say I had this problem too, I think it would be nice if something
along the lines of the solution you propsoed was added.

Ehud Lamm



Sun, 10 Aug 2003 02:37:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Ada 0y wish list: "with private"

2. Package parameters in generic packages

3. Passing a parameter Rexx to JCL and return a parameter to JCL

4. Turning a list value in a parameter into a list for eval without quasiquote/unquote

5. VHDL to Verilog - parameter which is log2 of another parameter

6. Parameter MyVar = ## Vs Parameter ( MyVar = ## )

7. parameter syntax for array parameter

8. language rules question: using a (passed in) parameter to define a parameter

9. Generic formal package parameter question

10. Tagged Types as Generic Formal Parameters (was comparison in generic packages)

11. A (sharp) package parameter problem

12. DCOracle and handling of package OUT parameters broken ?!

 

 
Powered by phpBB® Forum Software