CORE: add comprehensive type / arity checks, and corresponding tests.