Type verification on recursive function