Inferring the return type of functions