with Ada.Text_IO ; use Ada.Text_IO ;
procedure Main is
function Second_Order ( L_Func, R_Func : access function ( L, R : Integer) return Integer)
return access function ( L, R : Integer) return Integer is
function New_Function ( L, R : Integer) return Integer is
begin
return L_Func ( L, R) + R_Func ( L, R) ;
end New_Function;
begin
return New_Function'Unrestricted_Access;
end Second_Order;
function Plus ( L, R : Integer) return Integer is
begin
return L + R;
end Plus;
function Mult ( L, R : Integer) return Integer is
begin
return L * R;
end Mult;
begin
Ada.Text_IO .Put_Line ( Integer'Image ( Second_Order ( Plus'Access , Mult'Access ) ( 2 , 3 ) ) ) ;
-- (2+3) + (2*3) = 11
Ada.Text_IO .Put_Line ( Integer'Image ( Second_Order ( Plus'Access , Mult'Access ) ( 7 , 5 ) ) ) ;
-- (7+5) + (7*5) = 47
end Main;
d2l0aCBBZGEuVGV4dF9JTzsgdXNlIEFkYS5UZXh0X0lPOwoKcHJvY2VkdXJlIE1haW4gaXMKCiAgIGZ1bmN0aW9uIFNlY29uZF9PcmRlciAoTF9GdW5jLCBSX0Z1bmMgOiBhY2Nlc3MgZnVuY3Rpb24gKEwsIFIgOiBJbnRlZ2VyKSByZXR1cm4gSW50ZWdlcikKICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gYWNjZXNzIGZ1bmN0aW9uIChMLCBSIDogSW50ZWdlcikgcmV0dXJuIEludGVnZXIgaXMKICAgICAgCiAgICAgIGZ1bmN0aW9uIE5ld19GdW5jdGlvbiAoTCwgUiA6IEludGVnZXIpIHJldHVybiBJbnRlZ2VyIGlzCiAgICAgIGJlZ2luCiAgICAgICAgIHJldHVybiBMX0Z1bmMgKEwsIFIpICsgUl9GdW5jIChMLCBSKTsKICAgICAgZW5kIE5ld19GdW5jdGlvbjsKICAgICAgCiAgIGJlZ2luCiAgICAgIHJldHVybiBOZXdfRnVuY3Rpb24nVW5yZXN0cmljdGVkX0FjY2VzczsKICAgZW5kIFNlY29uZF9PcmRlcjsKCiAgIGZ1bmN0aW9uIFBsdXMgK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