Functional gravity