In his book "Analysis 1", Terence Tao writes:
Thus, from the point of view of logic, we can define equality on a however we please, so long as it obeys the reflexive, symmetry, and transitive axioms, and it is consistent with all other operations on the class of objects under discussion in the sense that the substitution axiom was true for all of those operations.
So can one for example define that two functions $f, g\colon A\to B$ are equal if they agree almost everywhere? Intuitively, I would say that this contradicts the axiom of substitution: For example, consider the following functions of the type $\mathbb R\to\mathbb R$: $f(x) = x$ for all $x$ and $g(y) = y$ for every $y\not = 3$, $g(3) = 4$. Then we have $f=g$ because of our definition (there are only finitely many arguments on which the functions disagree (in fact there's only one: $3$), so they are equal). But by the axiom of substitution, the following should hold: $f(3) = g(3)$. Now I am a bit confused.