This seems pretty cumbersome. Could the partial function's expected type be changed to avoid this change?