AddType - Maple Help

# Online Help

###### All Products    Maple    MapleSim

TypeTools

 AddType
 extend type system with user-defined type

 Calling Sequence AddType(typename, handler)

Parameters

 typename - symbol; name of the type handler - procedure or structured type

Description

 • A new type typename is installed in the type system.
 • The handler argument is either a procedure or a structured type describing the new type.
 • If handler is a procedure, then a type call of the form $\mathrm{type}\left(\mathrm{expr},\mathrm{typename}\right)$ results in a call to $\mathrm{handler}\left(\mathrm{expr}\right)$. Additional arguments can be passed to handler from a type call of the form $\mathrm{type}\left(\mathrm{expr},\mathrm{typename}\left(\mathrm{arg1},\mathrm{arg2},...\right)\right)$, which results in the call $\mathrm{handler}\left(\mathrm{expr},\mathrm{arg1},\mathrm{arg2},...\right)$. The handler argument, if it is a procedure, must return either true or false; no other return value is acceptable. It must also be prepared to handle any argument sequence that is passed to it.
 • If the handler argument is a structured type, then the type test is defined by the structured type interpreter as though the structured type were used directly in a call to type.
 • The AddType command returns NULL.

Examples

 > $\mathrm{TypeTools}\left[\mathrm{AddType}\right]\left(\mathrm{tff},'\left\{\mathrm{identical}\left(\mathrm{FAIL}\right),\mathrm{identical}\left(\mathrm{false}\right),\mathrm{identical}\left(\mathrm{true}\right)\right\}'\right)$
 > $\mathrm{type}\left(\mathrm{FAIL},'\mathrm{tff}'\right)$
 ${\mathrm{true}}$ (1)
 > $\mathrm{type}\left(\left[\mathrm{true},\mathrm{false}\right],'\mathrm{list}\left(\mathrm{tff}\right)'\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{TypeTools}\left[\mathrm{AddType}\right]\left(\mathrm{integer7},t↦\mathrm{evalb}\left(t::'\mathrm{integer}'\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{irem}\left(t,7\right)=0\right)\right)$
 > $\mathrm{type}\left(4,'\mathrm{integer7}'\right)$
 ${\mathrm{false}}$ (3)
 > $\mathrm{type}\left(28,'\mathrm{integer7}'\right)$
 ${\mathrm{true}}$ (4)
 > TypeTools[AddType]( pair, proc( expr, elementtype := anything )     type( expr, [ elementtype, elementtype ] ) end proc ):
 > $\mathrm{type}\left(\left[2,x\right],'\mathrm{pair}'\right)$
 ${\mathrm{true}}$ (5)
 > $\mathrm{type}\left(\left[2,x\right],'\mathrm{pair}\left(\mathrm{integer}\right)'\right)$
 ${\mathrm{false}}$ (6)
 > $\mathrm{type}\left(\left[2,3\right],'\mathrm{pair}\left(\mathrm{integer}\right)'\right)$
 ${\mathrm{true}}$ (7)

 See Also