gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gm2] Re: ISO strangeness


From: Peter P. Eiserloh
Subject: [Gm2] Re: ISO strangeness
Date: Tue, 4 Nov 2003 08:33:26 -0800
User-agent: Mutt/1.5.4i

Hello Gaius,

Yes, this is valid Modula-2.  Not only with ISO M2, but also with PIM3
(which I have).  The type [b] is an opaque type, which most compilers
implement as a pointer.  What it points to has to be defined later in
an implementation module.  In Modula-3 this is called revealing the
type.

This facility exists to allow abstract types, and hiding of
implementation details, while still maintaining type safety.


To quote from PIM3 (page 169)

   Definition modules imply the use of qualified export.  Type
   definitions may consist of the full specification of the type (in
   this case its export is said to be transparent), or they may consist
   of the type identifier only.  In this case the full specification
   must appear in the corresponding implementation module, and its export
   is said to be _opaque_.  The type is known in its importing modules by
   its name only, and all its properties are hidden.  Therefore, procedures
   operating on operands of this type, and in particular operating on
   its components, must bedefined in the same implementation module
   which hides the type's properties.  Opaque export is restricted to
   pointers.  Assignment and test for equality are applicable to all
   opaque types.

Wirth also has some examples starting on page 90 TableHandler, whose
definiton module defines an opaque type [Table].  Later on page 93, the
implementation module defines a TreePtr which is a pointer to a record,
and then the type definition:

    Table = TreePtr;


In sum, yes the facility you described is not only allowed but it use is
encouraged.  You simply used a bad choice (SYSTEM.ADDRESS) for the type
of pointer to which b.i was defined.


Peter P. Eiserloh


> Message: 1
> To: address@hidden
> From: Gaius Mulley <address@hidden>
> Date: Mon, 03 Nov 2003 21:37:50 +0000
> Subject: [Gm2] ISO strangeness
> 
> 
> Hi,
> 
> I've been examining some ISO code and it appears that (from the code)
> the following is legal:
> 
> DEFINITION MODULE a;
> IMPORT b;
> TYPE
>    i = b.i ;
> END a.
> 
> IMPLEMENTATION MODULE a;
> FROM b IMPORT i;
> END a.
> 
> DEFINITION MODULE b;
> TYPE
>    i;
> END b.
> 
> IMPLEMENTATION MODULE b;
> IMPORT SYSTEM;
> TYPE
>    i = SYSTEM.ADDRESS;
> END b.
> 
> I'd have thought that when compiling module, a, an error should be
> generated as the object, i, is being redeclared in the IMPLEMENTATION
> MODULE. Can anyone verify:
> 
>  +  that this is legal in ISO M2
>  +  and out of interest which compilers allow this
> 
> Thanks Gaius
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]