Fixes #29: refactor type and value checking

Not quite decorators yet, but already much less duplication. Not even sure
decorators are that useful in this context, because for some check the values
to be checked must first be computed.