# Should a pure function take all of the functions it calls as arguments?

After Wikipedia, if a function is pure, then:

[it] always evaluates the same result value given the same argument value(s).

So: if a function, let's call it f, calls another function, g, then it's behavior clearly depends on the structure of the function g. Should f take g as an argument in order to be pure?

• This is probably opinion based, but if I were to write down the semantics, each function would get an implicit argument with the environment where it can look up things like the function $g$. Jul 26, 2016 at 10:05
• I'm not sure what computation context you're considering, but usually g would be free inside of f. It wouldn't be an argument though, at least not in the traditional meaning of the word Jul 26, 2016 at 13:49

No, f doesn't have to take g as an argument. Wikipedia's definition is a bit informal. Also informally, the behavior of a pure function is also allowed to depend on the code of the program. Or, to put it another way, the code of the program is considered fixed, not something we vary, so we don't try to track dependences on it.

So, something like f(x) = 2*g(x) is fine: if g is pure, f will be too.

• By that definition, global constants are fine as well, correct?
– TLW
Jul 28, 2016 at 2:32
• @TLW, yes, that's right. Please, if you have a follow-up question, please post a new question, rather than using comments for that. thank you!
– D.W.
Jul 28, 2016 at 6:48

No. For an algebraic structure over a set you fix the set of function symbols and the set of variables from the start. Then you can think of functions as constants. (Technically constants are functions with zero argument but anyway.) Therefore calling (pure) functions does not disrupt the purity.

The fact that f calls g doesn't influence the purity. All that's required is that for a given input to f, f always returns the same output. That means g must be pure. It also means if someone changes g so it's impure, then f becomes impure, too. But at that point it's a different function.