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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Creating a generic package with and setting its type to that of a record Date: Wed, 28 Sep 2016 07:15:30 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="e5f31545d127a6738a4229c67d648b1c"; logging-data="14449"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6iGawM965pII10WNnUojIuqNk5aXo1hQ=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (darwin) Cancel-Lock: sha1:3rmk6crj2NUS9L3k9lS5s43hJfc= sha1:vi3/hBm/OcNYjWyvhHq21vnaXNk= Xref: news.eternal-september.org comp.lang.ada:31914 Date: 2016-09-28T07:15:30+01:00 List-Id: Andrew Shvets writes: > generic > type Custom_Record_Type is <>; > package Gener is > ... > > What I'd like to do is set the type to that of a record (which has > some overloaded operators, such as >, < and =.) Can this be done? If > so, how? I think you are looking for generic formal subprograms[1]. Something like generic type Custom_Record_Type is private; with function ">" (L, R; Custom_Record_Type) return Boolean is <>; with function "<" (L, R; Custom_Record_Type) return Boolean is <>; with function "=" (L, R; Custom_Record_Type) return Boolean is <>; package Gener is The 'is <>' notation means you don't need to supply an actual for this parameter if a matching one is visible at the point of instantiation. You could instantiate it for Integer, but I'm not sure what operation would be used if you tried "<=", for instance; the composition of your generic actuals, or the emergent "<=" of Integer. [1] https://en.wikibooks.org/wiki/Ada_Programming/Generics#Generic_formal_subprograms