Add type annotations, as requested by eliom#56.

Solved some benign type errors and two serious one on the way.