Better checking of derivations (closes #12); type-checking almost complete (closes #1).