Definition of a Structured Type in Maple - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Data Types : Type Checking : Types : type/structure

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(f)

the function f with (possibly zero) arguments of any type

 

| specfunc(type,f)

the function f with (possibly zero) type arguments

 

| anyfunc(type*)

any function of the given types

 

| specop(operator)

an operator or function expression with operands of any type

 

| specop(type,operator)

an operator or function expression with type operands

 

| anyop(type*)

any operator or function of the given types

 

| typefunc(type0)

a function of type type0 with arguments of any type

 

| 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(x)

the expression x with indices of any type

 

| specindex(type,x)

the expression x with all indices of the given type

 

| typeindex(type0)

an expression of type type0 with indices of any 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

 

| p(anything*)

type defined by a procedure `type/p`

 

| f(type*)

the function f 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 t1,...,tn. Thus, type(f, anyfunc(t1,...,tn)) is equivalent to the logical conjunction type(f, function) and type([op(f)], [t1,...,tn]).

• 

The type patfunc(t1,..., tn, t) matches any function with n or more arguments where the first n are of type t1,...,tn, and the remaining arguments are of type t.

• 

The type patfunc[reverse](t,t1,...,tn) matches any function with n or more arguments where the last n are of type t1,...,tn, and the preceding arguments are of type t.

• 

The type specfunc(t, n) matches the function n with 0 or more arguments of type t.  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 n and operands of type t. 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 T with 0 or more arguments of type t.  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

typestring&comma;string

false

(1)

typestring&comma;identicalstring

true

(2)

typex2&comma;nameinteger

true

(3)

typex2&comma;nameposint

false

(4)

typex2&comma;algebraicinteger

true

(5)

typex&plus;y12&plus;1&comma;`&+`name&comma;radical&comma;integer

true

(6)

typeabc&comma;`&*`algebraic&comma;algebraic&comma;algebraic

true

(7)

type&ExponentialE;x&comma;&ExponentialE;name

true

(8)

T:=TEXTline 1&comma;line 2&colon;

typeT&comma;TEXTstring

false

(9)

typeT&comma;TEXTstring&comma;string

true

(10)

typeT&comma;specfuncstring&comma;TEXT

true

(11)

typeT&comma;anyfuncstring

false

(12)

typeT&comma;anyfuncstring&comma;string

true

(13)

typeT&comma;typefuncstring&comma;symbol

true

(14)

typeT&comma;functionstring

true

(15)

typeFa&comma;b&comma;specopanything&comma;F

true

(16)

typea&plus;b&comma;specfuncanything&comma;`+`

false

(17)

typea&plus;b&comma;specopanything&comma;`+`

true

(18)

typea&plus;b&comma;specopanything&comma;`+`&comma;`*`

true

(19)

typex&comma;1&comma;name&comma;integer

true

(20)

typex&comma;1&comma;listinteger

false

(21)

typex&comma;1&comma;listname

false

(22)

typex&comma;1&comma;listname&comma;integer

true

(23)

typeT&comma;nameTEXTstring&comma;string

false

(24)

type&apos;T&apos;&comma;nameTEXTstring&comma;string

true

(25)

typeab&comma;&apos;specindexanything&comma;a&apos;

true

(26)

typeab&comma;&apos;specindexinteger&comma;a&apos;

false

(27)

typea2&comma;&apos;specindexinteger&comma;a&apos;

true

(28)

typea2&comma;a string&comma;&apos;anyindexinteger&comma;string&apos;

true

(29)

typea2&comma;a string&comma;&apos;anyindexstring&comma;integer&apos;

false

(30)

typea2&comma;&apos;typeindexinteger&comma;symbol&apos;

true

(31)

Test for angles that have a rational cosine.

type&pi;3&comma;&apos;rational &under cos&apos;

true

(32)

type&pi;4&comma;&apos;rational &under cos&apos;

false

(33)

Test for an arbitrary data structure containing positive integers.

type2&comma;3&comma;4&comma;&apos;listposint &under convert&comma;list&apos;

true

(34)

type1&comma;2&verbar;3&comma;52&comma;&apos;listposint &under convert&comma;list&apos;

false

(35)

See Also

type, type/literal, type/surface


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam