home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / ada / 2367 < prev    next >
Encoding:
Text File  |  1992-08-14  |  2.0 KB  |  72 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!gatech!darwin.sura.net!mips!think.com!linus!linus.mitre.org!mbunix.mitre.org!costello
  3. From: costello@mbunix.mitre.org (Costello)
  4. Subject: ADT functions working with multiple derived types
  5. Message-ID: <1992Aug14.184008.8484@linus.mitre.org>
  6. Sender: news@linus.mitre.org (News Service)
  7. Nntp-Posting-Host: mbunix.mitre.org
  8. Organization: The MITRE Corp., Bedford, Ma.
  9. Distribution: usa
  10. Date: Fri, 14 Aug 1992 18:40:08 GMT
  11. Lines: 59
  12.  
  13. Hi Folks,
  14.     I have created an Abstract Data Type (ADT). That is, I have a package
  15. that declares a type and functions which work on that type.  Now, I can
  16. derive from that ADT type and then all of those functions are available
  17. to me with the new type.  This works fine.
  18.    
  19.     The problem arises when, in the ADT package, I declare two types and 
  20. have functions which work on both types.  When I then do my deriving I 
  21. derive on both types.  Now, when I invoke the function which is supposed
  22. to work on both types I get a compiler error:
  23.  
  24. >>>>SEMANTIC : Unresolvable expression <8.3, 8.7>
  25.  
  26. I have concluded that ADTs can only work on one type. Is this correct?
  27.  
  28. Here is an example.  Suppose we have the ADT called junk:
  29.  
  30. package junk is
  31.    subtype one is integer range 1..10;
  32.    type two is record
  33.       x : integer range 1..20;
  34.    end record;
  35.    function p (a : one) return two;
  36. end junk;
  37.  
  38. package body junk is
  39.    function p (a : one) return two is
  40.    r : two;
  41.    begin
  42.       r.x := a;
  43.       return r;
  44.    end p;
  45. end junk;
  46.  
  47. Here is a procedure to test the ADT:
  48.  
  49. with junk; use junk;
  50.  
  51. procedure p_test is
  52. type new1 is new one;
  53. type new2 is new two;
  54. g: new1;
  55. h : two;
  56. begin
  57.     g := 5;
  58.     h := p(g);
  59. end p_test;
  60.  
  61. When I compile this procedure I get the above error message.
  62. Note that when I change the second assignment statement to:
  63.   
  64.    h := two(p(g));
  65.  
  66. then I don't get the compiler error.  If you could shed some 
  67. light on this I would appreciate it.  Please send replies to:
  68.  
  69.    costello@mitre.org
  70.  
  71. Thanks.  /Roger
  72.