Typing and type error diagnosis with Constraint Handling Rules