Core functional representation

Resolves #710 when merged, but not even nearly ready yet.

Not sure there is much to talk about yet, I was hoping to get a bit further with it, so everything is subject to change still.
It would just reduce the complexity of the CoreFn representation, which potentially makes optimisations more widely applicable.