Learning to Mitigate Externalities: the Coase Theorem with Hindsight Rationality