MathObject type checking doesn't look for
equal types, but rather
compatible types. So if you are asking for a complex number, for example, and the student enters a real number (no
i
), there is no type warning, because the real can be promoted to a complex at the time the check is performed.
Similarly, if the question asks for a (real) number, and the student enters a string like DNE
or an infinity like -inf
, there is no type warning because the question could have been asking for a limit, and DNE or -infinity could be legitimate answers for that, and even if they are not correct, you don't want to give a warning message if student enter them.
If an answer is a string, however, it is not clear what other types of answers could be reasonable (but wrong) ones. For example, if you were asking for points (x,y) where a function is undefined, the answer could be none
, but the string answer checker doesn't know if points are valid answers or not, and whether they should get a type warning or not.
In order to work around this, you should provide an object of the correct type whenever you use a string answer so that the answer checker can properly determine the expected type of answer. By default it uses a real, but if you are expecting some other type of answer, then you must supply an example to be used for type checking.
This is done by providing a typeMatch
option to the answer checker, as in
ANS(String("none")->cmp(typeMatch => Point(1,2)));
which would allow the student to enter points without causing a type warning.
In your case, you would want to provide a Matrix as the typeMatch
parameter. The only complication is that you are within a MultiAnswer
object, and so don't have access to the individual answer checkers directly. So you can use the cmpDefaults
trick again to provide them for the string answers; e.g.,
Context()->{cmpDefaults}{String}{typeMatch} = Matrix([1,0],[0,1]);
This will allow matrix answers to be accepted without type warnings in the string answer blanks.
As for checkTypes
, the Wiki reference you cite is somewhat misleading. The MultiAnswer
object always does type-checking, but normally it only calls your checker
if the types of the student answers are actually equal to the types of the correct answers (not just compatible, but equal). Setting checkTypes
to 0 allows compatible types to be passed to your checker
, but not arbitrary types. See the POD documention for parserMultiAnswer.pl for the most accurate information.
The reason checkTypes=>0
worked in the Wiki example is because strings are compatible with any answer, so the type matching never causes a warning for that. But the checker
would not normally be called if the string and formula were reversed, because the types must be exact (not just compatible). Setting checkTypes=>0
loosened that requirement to be just compatible types, so the checker
was called.
Anyway, hope that does what you need.
Davide