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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,93590e6c825ce084,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "(see below)" Newsgroups: comp.lang.ada Subject: using interface types: guru assistance begged Date: Thu, 06 Jul 2006 16:20:21 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Trace: individual.net bxX0dB5943/5SVwR3Si6uADn2+8tnHPdsa8v3EWognQgPm1foy User-Agent: Microsoft-Entourage/11.2.4.060510 Thread-Topic: using interface types: guru assistance begged Thread-Index: AcahD7IG8JAUEg0CEduHSAARJIjQTg== Xref: g2news2.google.com comp.lang.ada:5541 Date: 2006-07-06T16:20:21+01:00 List-Id: I am trying to learn how to use Ada 2005's interface types, using GNAT GPL 2006 on MacOS X, with an example along the following lines (much trimmed): generic type a_member_type is (<>); package generic_sets_interface is type a_set is interface; function is_empty (trial_set : a_set) return Boolean is abstract; pragma Inline(is_empty); function empty_set return a_set is abstract; pragma Inline(empty_set); function bit (candidate : a_member_type) return a_word_set; pragma Inline (bit); ... end generic_sets_interface; ...... with generic_sets_interface; generic type a_basis_type is mod <>; type a_member_type is (<>); package generic_word_masks is package generic_word_masks_interface is new generic_sets_interface(a_member_type); type a_set is new generic_word_masks_interface.a_set with private; function is_empty (trial_set : a_word_set) return Boolean; pragma Inline(is_empty); function empty_set return a_word_set; pragma Inline(empty_set); ... private type a_word_set is new generic_word_masks_interface.a_set with record basis : a_basis_type; end record; end generic_word_masks; ...... package body generic_word_masks is function shift_right (v : a_basis_type; amount : Natural) return a_basis_type; pragma Import(Convention => Intrinsic, Entity => shift_right); empty_basis : constant a_basis_type := 0; function is_empty (trial_set : a_word_set) return Boolean is begin return (trial_set.basis = empty_basis); end is_empty; function empty_set return a_word_set is begin return a_word_set'(basis => empty_basis); end empty_set; function bit (candidate : a_member_type) return a_word_set is begin return a_word_set'(basis => shift_left(1, Natural(a_member_type'Pos(candidate)))); end bit; ... end generic_word_masks ; As written this compiles and runs correctly. However, I would prefer the derivation of a_word_set to be private, thus: private with generic_sets_interface; generic type a_basis_type is mod <>; type a_member_type is (<>); package generic_word_masks is type a_word_set is private; function is_empty (trial_set : a_word_set) return Boolean; pragma Inline(is_empty); function empty_set return a_word_set; pragma Inline(empty_set); ... private package generic_word_masks_interface is new generic_sets_interface(a_member_type); type a_word_set is new generic_word_masks_interface.a_set with record basis : a_basis_type; end record; end generic_word_masks; But when I do this, the instantiation in my test program fails, thus: type i32 is mod 2**32; type fivetrack is range 0..31; 13. package word_masks_32 is new generic_word_masks(i32, fivetrack); | >>> instantiation error at generic_word_masks.ads:76 >>> type must be declared abstract or "is_empty" overridden >>> "is_empty" has been inherited at generic_word_masks.ads:76, instance at line 13 >>> "is_empty" has been inherited from subprogram at generic_sets_interface.ads:13, instance at generic_word_masks.ads:74, instance at line 13 >>> instantiation error at generic_word_masks.ads:76 >>> type must be declared abstract or "empty_set" overridden >>> "empty_set" has been inherited at generic_word_masks.ads:76, instance at line 13 >>> "empty_set" has been inherited from subprogram at generic_sets_interface.ads:16, instance at generic_word_masks.ads:74, instance at line 13 And so on, for all of the subprograms declared in generic_word_masks. Can anyone tell me what I am doing wrong here, and whether there is any way to achieve the desired information hiding? With thanks. -- Bill Findlay chez blueyonder.co.uk