From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,daf6d89212a75f42,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!indigo.octanews.net!news-out.octanews.net!mauve.octanews.net!news-out.readnews.com!postnews3.readnews.com!not-for-mail Date: Sun, 03 Feb 2008 13:35:44 -0500 From: "Peter C. Chapin" User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Using a generic instance to implement a public subprogram? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <47a609b8$0$23664$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: c8a84863.news.sover.net X-Trace: DXC=2ZK_ZbNXdW2=RT:S6`J8?5K6_LM2JZB_3 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