WeBWorK Problems

parserMultiAnswer: checkTypes checking types (when it shouldn't?)

Re: parserMultiAnswer: checkTypes checking types (when it shouldn't?)

by Davide Cervone -
Number of replies: 0
Gavin:

Am I missing something in how checkTypes should be working?

Yes. The checkTypes parameter controls whether the object types must match exactly or not. Some typechecking is always performed. This is as described in the POD documentation for parserMultiPart.pl.

For example, for a numeric answer, if the student types an infinity or a word (like "DNE" or "None") there is no warning issued about mismatched types, even though these types are not an exact match. They are "compatible" types, which means it makes sense to simply report "incorrect" rather than give a warning about the wrong kind of answer. On the other hand, if the student typed a list of numbers, or a formula, rather than a number, then the warning message is issued.

This is the always the case, no matter whether checkTypes is 1 or 0. When checkTypes=>1 this means that the answer checker will only be called when the student's answer is exactly the same type as the correct answer (not just a compatible one). That means your checker can use the student answer without having to worry about whether it is the right type or not. For example, for a numeric answer, you can do arithmetic with the student answer without having to check whether they actually entered "DNE" or an infinity. But some type-checking is always performed. I suppose the parameter is badly named and should probably have been "exactTypes" or "matchingTypes" or something like that.

I don't recommend using Paul's suggestion of using Formula objects here, as that will only eliminate a few of the type-match errors, and will produce inappropriate errors in other cases. For example, if the student answers 1,2 for the second answer, you will get a type warning indicating that the problem was expected a formula returning a number, but you are really looking for a number, not a formula.

Currently there is no option to prevent the MultiAnswer object from doing any typechecking. The only thing I can think of to accomplish that is to make a subclass of the Real class and override the typeMatch method so that is always returns true. For example

    package user::Real;
    our @ISA = ('Value::Real');
    sub typeMatch {1;}
    package main;
    sub UserReal {user::Real->new(@_)}
defines a new subclass of Real, and you can then use
    @yvals = (UserReal(3.962), UserReal(0.0003));
to get instances of this new class for use in the MultiAnswer. You should then use
    Real(0)->typeMatch($stu[0]) && $cor[0] == $stu[0]
to check if the student's answer is a Real object (since $cor[0] is a UserReal, where typeMatch will always return 1) and equals the correct answer.

Davide