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.
I don't feel strongly about it either way though, and it may prove difficult to make good JS if we do drop `case` so may not be workable in the end regardless.