simplified type inference code from the eopl book