In JavaScript we can define function composition as using a function which takes two functions f and g, to produce a new function:
function o(f, g) {
return function(x) {
return f(g(x));
}
}
This seems obvious, but my question is, does the runtime interpreter/compiler actually calculate f(g(x))?
Say we have some large data like an array with many elements, and is the previously composed function o as the f(g(x)) by the prior calculation faster than uncomposed f(g(x)) ?
Perhaps, in this case, o(f, g) as merely a macro expression of f(g(x))?
And if it's a macro, perhaps, the performance doesn't make much difference?
It may depends on the runtime environment, I especially interested in V8 engine for Chrome/node.js.
Haskell as a language of lazy evaluation strategy theoretically compose functions, am I correct? Does GHC actually calculate to compose functions?