From: "Peter C. Chapin" <pchapin@sover.net>
Subject: Using a generic instance to implement a public subprogram?
Date: Sun, 03 Feb 2008 13:35:44 -0500
Date: 2008-02-03T13:35:44-05:00 [thread overview]
Message-ID: <47a609b8$0$23664$4d3efbfe@news.sover.net> (raw)
I'm trying to implement a public subprogram (actually several) by
instantiating a generic. I'm getting an ambiguous (to me) error message
from GNAT GPL 2007. Here is a complete, compilable example that contains
the essence of what I'm trying to do:
package Check is
type Numeric_Type is digits 12;
type Vector is private;
function Sqrt(V : Vector) return Vector;
-- Imagine other operations like Sqrt.
private
type Vector is array(0..15) of Numeric_Type;
end Check;
The package body defines a generic function for applying an operation to
a vector and then tries to instantiate it in order to implement function
Sqrt.
with Ada.Numerics.Generic_Elementary_Functions;
package body Check is
package Elementary_Functions is
new Ada.Numerics.Generic_Elementary_Functions(Numeric_Type);
generic
with function Operation(Value : Numeric_Type) return Numeric_Type;
function Unary_Operation(V : Vector) return Vector;
function Unary_Operation(V : Vector) return Vector is
Result : Vector;
begin
for I in 0 .. 15 loop
Result(I) := Operation(V(I));
end loop;
return Result;
end;
function Sqrt is
new Unary_Operation(Operation => Elementary_Functions.Sqrt);
end Check;
GNAT says this:
check.adb:3:14: missing body for "Sqrt" declared at check.ads:5
check.adb:21:13: "Sqrt" conflicts with declaration at check.ads:5
check.adb:21:13: instantiation cannot provide body for it
The first message I understand. The last two I'm not clear about. Is
GNAT telling me that my declarations conflict in some way and because of
that it can't do the instantiation, or is the instantiation the *cause*
of the conflict? Is it possible to do what I'm trying to do here?
Thanks!
Peter
next reply other threads:[~2008-02-03 18:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-03 18:35 Peter C. Chapin [this message]
2008-02-03 19:27 ` Using a generic instance to implement a public subprogram? Gautier
2008-02-03 19:46 ` Peter C. Chapin
2008-02-03 20:37 ` Dmitry A. Kazakov
2008-02-05 1:58 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox