Move implementation details of 'function' data type.

In addition, make 'function' its own "module" and update references in
other modules to account for this change.