Consider a measure space $(\Omega, \mathcal{F}, \mu)$ and let $f,g: \Omega \to \mathbb{R}$ be $\mathcal{F}$-measurable integrable functions. If
$$\int_A f d \mu = \int_A g d \mu$$
for all $A \in \mathcal{F}$, then $f = g$ $\mu$-a.e.
Here is the proof my course notes provide:
It is sufficient to prove that $\mu\{f < g\} = 0 = \mu\{g < f\}$. By symmetry, we only prove the first equality.
Put $$h:= (g-f)I_{\{g > f\}}$$
Then $$\int_\Omega h d\mu = \int_{\{f<g\}}(g-f) = 0$$ since $f,g$ are integrable functions. Since $h \geq 0$, it follows that $h = 0$ a.e. and thus $\mu\{g > f\} \leq \mu\{h \neq 0\} = 0$. This ends the proof.
My question: Can we generalise this to integrable functions $f,g: \Omega \to [-\infty, \infty]$ (note the change of codomain).
I think the proof generalises: the function $h$ is well defined because we can only have $\infty - (-\infty) = \infty$. Is this correct?