First implementation of typechecker
Merge branch 'martyn82'