ModuleType
refine the type checking when an object is used as a type
Calling Sequence
Description
Examples
Compatibility
module() export ModuleType, ...; ... end module;
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.
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 ):
type⁡i2,MyInt
true
type⁡i2,MyInt⁡prime
type⁡i2,MyInt⁡even
type⁡i2,MyInt⁡odd
false
type⁡i5,MyInt
type⁡i5,MyInt⁡prime
type⁡i5,MyInt⁡even
type⁡i5,MyInt⁡odd
type⁡i9,MyInt
type⁡i9,MyInt⁡prime
type⁡i9,MyInt⁡even
type⁡i9,MyInt⁡odd
The ModuleType command was introduced in Maple 16.
For more information on Maple 16 changes, see Updates in Maple 16.
See Also
::
module
ModuleApply
ModuleCopy
ModuleDeconstruct
ModuleIterator
ModuleLoad
ModulePrint
ModuleUnload
Object
object/builtins
Object/overview
procedure
type
Download Help Document