ModuleType - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


ModuleType

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

 

Calling Sequence

Description

Examples

Compatibility

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 ):

typei2,MyInt

true

(1)

typei2,MyIntprime

true

(2)

typei2,MyInteven

true

(3)

typei2,MyIntodd

false

(4)

typei5,MyInt

true

(5)

typei5,MyIntprime

true

(6)

typei5,MyInteven

false

(7)

typei5,MyIntodd

true

(8)

typei9,MyInt

true

(9)

typei9,MyIntprime

false

(10)

typei9,MyInteven

false

(11)

typei9,MyIntodd

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

::

module

ModuleApply

ModuleCopy

ModuleDeconstruct

ModuleIterator

ModuleLoad

ModulePrint

ModuleUnload

Object

object/builtins

Object/overview

procedure

type