Implement bottom-up typechecker