Definition of a Structured Type in Maple
|
Description
|
|
•
|
A structured type is a Maple expression other than a symbol that can be interpreted as a type. A typical example would be set(name=algebraic). This specifies a set of equations whose left-hand sides are (variable) names, and whose right-hand sides are of type algebraic.
|
•
|
This file first gives a formal grammatical description of the valid structured types, then provides notes on some of the special types, and lastly gives examples.
|
•
|
In the formal definition below, read ``::='' to mean ``is defined to be'', ``|'' to mean ``or'', and ``*'' to mean ``zero or more occurrences of''.
|
|
Syntax
|
Matches
|
|
|
|
type ::=
|
{ type* }
|
alternation; any of the types
|
|
| [ type* ]
|
a list of the given types
|
|
| complex(numeric)
|
match a complex numerical constant exactly
|
|
| string
|
match a string exactly
|
|
| symbol
|
a system, procedural, or assigned type
|
|
| type = type
|
an equation of the corresponding types
|
|
| type <> type
|
an inequality of the corresponding types
|
|
| type < type
|
a relation of the corresponding types
|
|
| type <= type
|
a relation of the corresponding types
|
|
| type > type
|
a relation of the corresponding types
|
|
| type >= type
|
a relation of the corresponding types
|
|
| type .. type
|
a range of the corresponding types
|
|
| type and type
|
an AND of the corresponding types
|
|
| type or type
|
an OR of the corresponding types
|
|
| not type
|
a NOT of the corresponding type
|
|
| type &+ type ...
|
a sum of the corresponding types
|
|
| type &* type ...
|
a product of the corresponding types
|
|
| type ^ type
|
a power of the corresponding types
|
|
| type || type
|
a concatenation of the corresponding types
|
|
| 'type'
|
an unevaluated expression of the given type
|
|
| fcntype
|
a function or a special type
|
|
| name[type*]
|
an indexed reference of the given types
|
|
|
|
fcntype ::=
|
set(type)
|
a set of elements of the given type
|
|
| list(type)
|
a list of elements of the given type
|
|
| Or(type*)
|
any of the given types
|
|
| And(type*)
|
all of the given types
|
|
| Not(type)
|
not the given type
|
|
| identical(expr)
|
an expression identical to expr
|
|
| specfunc(type,foo)
|
the function foo with type arguments
|
|
| anyfunc(type*)
|
any function of the given types
|
|
| specop(type,operator)
|
an operator or function expression with type operands
|
|
| anyop(type*)
|
any operator or function of the given types
|
|
| typefunc(type,type0)
|
a function of type type0 with type arguments
|
|
| patfunc(type*,type)
|
a function matching the first type argument(s), with all remaining arguments matching the last type
|
|
| patfunc[reverse](type,type*)
|
a function matching the last type argument(s), with all preceding arguments matching the first type
|
|
| specindex(type,foo)
|
the expression foo with all indices of the given type
|
|
| typeindex(type,type0)
|
an expression of type type0 with all indices of the given type
|
|
| anyindex(type*)
|
any indexed expression with indices of the given types
|
|
| patindex(type*,type)
|
an indexed expression matching the first type argument(s), with all remaining arguments matching the last type
|
|
| patindex[reverse](type,type*)
|
an indexed expression matching the last type argument(s), with all preceding arguments matching the first type
|
|
| function(type)
|
any function with type arguments
|
|
| name(type)
|
any name with a value of the given type
|
|
| patlist(type*,type)
|
a list matching the first type argument(s), with all remaining arguments matching the last type
|
|
| patlist[reverse](type,type*)
|
a list matching the last type argument(s), with all preceding arguments matching the first type
|
|
| foo(anything*)
|
type defined by a procedure `type/foo`
|
|
| foo(type*)
|
the function foo of the given types
|
|
| `+`(type)
|
a sum of terms of the given type
|
|
| `*`(type)
|
a product of factors of the given type
|
|
| `&+`(type*)
|
a sum of terms in which the nth term is of the nth type specified in type*
|
|
| `&*`(type*)
|
a product of factors in which the nth factor is of the nth type specified in type*
|
|
| type &under func
|
an expression expr so that func(expr) is of type type
|
|
| type &under (func, arg1, arg2)
|
an expression expr so that func(expr, arg1, arg2) is of type type
|
|
|
•
|
Square brackets [] are used to check for a fixed argument sequence. The type [name, set] matches a list with exactly two arguments: a name followed by a set.
|
•
|
Set brackets {} are used for alternation. The type {set(name), list(integer)} matches either a set of names, or a list of integers.
|
•
|
The type anything matches any expression except a sequence.
|
•
|
The type identical(expr) matches the expression expr identically. If there is more than one expr (i.e. identical(expr1,expr2,...)), then this type matches any one of the exprN identically.
|
•
|
The type anyfunc(t1, ..., tn) matches any function with n arguments of type . Thus, type(f, anyfunc(t1,...,tn)) is equivalent to the logical conjunction type(f, function) and type([op(f)], [t1,...,tn]).
|
•
|
The type specfunc(t, n) matches the function with 0 or more arguments of type . Thus, type(f, specfunc(t, n)) is equivalent to the logical conjunction type(f, function) and op(0,f) = n and type([op(f)], list(t)). Instead of a single name n, a set of names may be passed as the second parameter to the specfunc type constructor. In this case, an expression matches if it is a function call with any of the names in the set as the 0-th operand. Thus, type(f,specfunc(t,{n1,n2,...,nk})) is equivalent to type(f,specfunc(t,n1)) or type(f,specfunc(t, n2)) or ... or type(f,specfunc(t,nk)).
|
•
|
The type specop(t, n) matches an operator expression or function with zeroth operand and operands of type . It is similar to the specfunc type constructor, but also matches expressions, for example, sums, products, and relations, as well as functions. As for the specfunc type constructor, the second parameter may be a set of names rather than just a single name.
|
•
|
The type typefunc(t, T) matches a function of type with 0 or more arguments of type . Thus, type(f, typefunc(t, T)) is equivalent to the logical conjunction type(f, function) and type([op(0,f)], [T]) and type([op(f)], list(t)).
|
•
|
Analogous to specfunc, anyfunc, typefunc, patfunc, and patfunc[reverse], the type constructors specindex, anyindex, typeindex, patindex, and patindex[reverse] can be used to test for expressions with indices of prescribed types and the type constructors patlist and patlist[reverse] can be used to test for lists with elements of prescribed types.
|
•
|
The type type &under func describes expressions expr for which func(expr) is of type type. The second form of this type takes an arbitrary number of extra arguments for func; in particular, type &under (func, arg1, arg2, ...) describes expressions expr for which func(expr, arg1, arg2, ...) is of type type.
|
|
|
Examples
|
|
>
|
|
| (1) |
>
|
|
| (2) |
>
|
|
| (3) |
>
|
|
| (4) |
>
|
|
| (5) |
>
|
|
| (6) |
>
|
|
| (7) |
>
|
|
| (8) |
>
|
|
>
|
|
| (9) |
>
|
|
| (10) |
>
|
|
| (11) |
>
|
|
| (12) |
>
|
|
| (13) |
>
|
|
| (14) |
>
|
|
| (15) |
>
|
|
| (16) |
>
|
|
| (17) |
>
|
|
| (18) |
>
|
|
| (19) |
>
|
|
| (20) |
>
|
|
| (21) |
>
|
|
| (22) |
>
|
|
| (23) |
>
|
|
| (24) |
>
|
|
| (25) |
>
|
|
| (26) |
>
|
|
| (27) |
>
|
|
| (28) |
>
|
|
| (29) |
>
|
|
| (30) |
>
|
|
| (31) |
Test for angles that have a rational cosine.
>
|
|
| (32) |
>
|
|
| (33) |
Test for an arbitrary data structure containing positive integers.
>
|
|
| (34) |
>
|
|
| (35) |
|
|