A modal theory of function