comp.lang.ada
 help / color / mirror / Atom feed
From: EGarrulo <egarrulo@gmail.com>
Subject: How do you specialize a generic function from a nested function?
Date: Sun, 26 Jul 2015 01:29:35 -0700 (PDT)
Date: 2015-07-26T01:29:35-07:00	[thread overview]
Message-ID: <b18f6aba-3311-4497-a3fc-72dc3cef94be@googlegroups.com> (raw)

I am trying to write a generic predicate that negates a supplied predicate.  The generic predicate compiles, but the compilation of client code fails with "generic subprogram cannot be called" (because the client code supplies a nested predicate, I suppose).  Here is the code (see the comment in the last file).

------------- negate.ads ------------------

generic
   type Value_Type is private;
   with function Predicate (Value : Value_Type) return Boolean;
   -- I have also tried with:
   -- Predicate : access function (Value : Value_Type) return Boolean;
function Negate (Value : Value_Type) return Boolean;

------------- negate.adb ------------------

function Negate (Value : Value_Type) return Boolean is
begin
   return not Predicate (Value);
end Negate;

------------- test.adb ------------------

with Negate;

procedure test is
   function Is_Zero (Value: Integer) return Boolean is (Value = 0);

   Is_Not_Zero : access function (Value: Integer) return Boolean 
   := Negate(Integer, Is_Zero'Access); -- <<== ##### ERROR HERE #####
begin
   null;
end test;

--------------------------------------


What is wrong?  And -- in any case -- could the code be simplified?  Thank you.


             reply	other threads:[~2015-07-26  8:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-26  8:29 EGarrulo [this message]
2015-07-26  9:09 ` How do you specialize a generic function from a nested function? Dmitry A. Kazakov
replies disabled

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