User:Coderjoe/Sandbox2
<lang Ada> with Ada.Text_IO; with Ada.Numerics.Generic_Elementary_Functions; procedure Program is
generic type Number_Type is private; with function F(X : Number_Type) return Number_Type; with function G(X : Number_Type) return Number_Type; function Compose(X : Number_Type) return Number_Type; function Compose(X : Number_Type) return Number_Type is begin return F(G(X)); end; type Function_Type is access function(X : Float) return Float; function sqr(X : Float) return Float is begin return X * X; end; package Math is new Ada.Numerics.Generic_Elementary_Functions(Float); type Function_List is array(Natural range <>) of Function_Type; functions : Function_List := (Math.sin'Access, Math.cos'Access, Program.sqr'Access); inverts : Function_List of Function_Type := (Math.arcsin'Access, Math.arccos'Access, Math.sqrt'Access);
begin
for i in functions'Range loop declare
function C is new Compose(Float, functions(i).all, inverts(i).all);
begin
Ada.Text_IO.Put_Line(Float'Image(C(0.5)));
end; end loop;
end Program;
</lang>