A Theory of Adaptation