Type representing exactly one object

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.


testtype(obj, (t_obj))


testtype(x, Type::Singleton(y)) is equivalent to bool(x = y).

The call testtype(obj, Type::Singleton(t_obj)) is equivalent to bool(x = y), but the latter is faster.

Type::Singleton can be used to create combined types, especially in conjunction with Type::Union, Type::Equation and other types expecting type information for subexpressions (see Example 2).

This type does not represent a property.


Example 1

Check, if x is really x:

testtype(x, Type::Singleton(x))

But the next call does the same:

bool(x = x)

Example 2

Type::Singleton exists to create special testing expressions:

T := Type::Union(Type::Singleton(hold(All)), Type::Constant):

With the type T the option All and any constant can be identified with one call of testtype:

testtype(4, T), testtype(hold(All), T), testtype(x, T)

But (e.g., in procedures) the following example works faster:

test := X -> testtype(X, Type::Constant) or bool(X = hold(All)):
test(4), test(hold(All)), test(x)

One way to test a list of options for syntactical correctness is the following:

T := Type::Union(
       // Name = "..."
       Type::Equation(Type::Singleton(hold(Name)), DOM_STRING),
       // Mode = n, n in {1, 2, 3}
                      Type::Interval([1,3], Type::Integer)),
       // Quiet
testtype((Name = "abcde", Quiet), Type::SequenceOf(T))

We only allow the values 1, 2, and 3 for Mode, however:

testtype((Quiet, Mode = 0), Type::SequenceOf(T))

Obviously, it would be a good idea to tell the user which options we could not grok:

error("Unknown option(s): ".expr2text(
        select((Quiet, Mode = 0), 
               not testtype, Type::SequenceOf(T))))
Error: Unknown option(s): Mode = 0
delete T, test:



Any MuPAD® object


Any object to identify

Return Values

See testtype

See Also

MuPAD Functions

Was this topic helpful?