ModuleType - Maple Help

# Online Help

###### All Products    Maple    MapleSim

ModuleType

refine the type checking when an object is used as a type

 Calling Sequence module() export ModuleType, ...; ... end module;

Description

 • A module can be passed as the type specification to a call to type or in a :: expression. By default a module is considered the type of another module if and only if they both share the same module definition. This is true of all objects of the same class. The ModuleType method allows a module to refine the type check when a module is given as a type.
 • If a module that defines a ModuleType procedure is given as the type, and the given expression is a module matching that type, the ModuleType procedure will be called to further refine the type checking.
 • The calling sequence of a ModuleType procedure is:
 > export ModuleType::static := proc( M, typ, arg1, ... )

M : is the module that is being tested to see if it matches type typ

typ : is the type whose ModuleType procedure was called

arg1, ... : additional argument specified with the type, typ(arg1, ... )

 • The ModuleType routine should not make type checks using its containing module as a type.  This can lead to infinite recursion.
 • An object can implement a type override to allow the object to determine if it matches various types.  For more information, see the object/builtins page.

Examples

 > module MyInt()     option object;     local value;     export set::static := proc( obj::MyInt, v::integer )         obj:-value := v;     end;     export ModuleType::static := proc( obj, typ, arg )         if( _npassed = 2 ) then             true;         elif ( arg = 'prime' ) then             :-type( obj:-value, 'prime' );         elif ( arg = 'odd' ) then             :-type( obj:-value, 'odd' );         elif ( arg = 'even' ) then             :-type( obj:-value, 'even' );         end;     end;     export ModuleApply::static := proc( )         Object( MyInt, _passed );     end;     export ModuleCopy::static := proc( self::MyInt, proto::MyInt, v::integer, \$ )         if ( _npassed = 2 ) then             self:-value := 0;         else             self:-value := v;         end;     end; end: i2 := MyInt( 2 ): i5 := MyInt( 5 ): i9 := MyInt( 9 ):
 > $\mathrm{type}\left(\mathrm{i2},\mathrm{MyInt}\right)$
 ${\mathrm{true}}$ (1)
 > $\mathrm{type}\left(\mathrm{i2},'\mathrm{MyInt}'\left(\mathrm{prime}\right)\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{type}\left(\mathrm{i2},'\mathrm{MyInt}'\left(\mathrm{even}\right)\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{type}\left(\mathrm{i2},'\mathrm{MyInt}'\left(\mathrm{odd}\right)\right)$
 ${\mathrm{false}}$ (4)
 > $\mathrm{type}\left(\mathrm{i5},\mathrm{MyInt}\right)$
 ${\mathrm{true}}$ (5)
 > $\mathrm{type}\left(\mathrm{i5},'\mathrm{MyInt}'\left(\mathrm{prime}\right)\right)$
 ${\mathrm{true}}$ (6)
 > $\mathrm{type}\left(\mathrm{i5},'\mathrm{MyInt}'\left(\mathrm{even}\right)\right)$
 ${\mathrm{false}}$ (7)
 > $\mathrm{type}\left(\mathrm{i5},'\mathrm{MyInt}'\left(\mathrm{odd}\right)\right)$
 ${\mathrm{true}}$ (8)
 > $\mathrm{type}\left(\mathrm{i9},\mathrm{MyInt}\right)$
 ${\mathrm{true}}$ (9)
 > $\mathrm{type}\left(\mathrm{i9},'\mathrm{MyInt}'\left(\mathrm{prime}\right)\right)$
 ${\mathrm{false}}$ (10)
 > $\mathrm{type}\left(\mathrm{i9},'\mathrm{MyInt}'\left(\mathrm{even}\right)\right)$
 ${\mathrm{false}}$ (11)
 > $\mathrm{type}\left(\mathrm{i9},'\mathrm{MyInt}'\left(\mathrm{odd}\right)\right)$
 ${\mathrm{true}}$ (12)

Compatibility

 • The ModuleType command was introduced in Maple 16.
 • For more information on Maple 16 changes, see Updates in Maple 16.

 See Also