In composition of two mappings, can the outer mapping access the arguments of the inner mapping? In composition of two mappings, can the outer mapping access the arguments of the inner mapping?


*

*Here is an example to illustrate my question and my thought.
E.g. $f: \cup_{n \in \mathbb N} \mathbb R^n \to \mathbb R$ is taking
sum, i.e.  $f(x_1, \dots, x_n) =  \sum_i x_i$. Note here $n$ can
vary in $\mathbb N$.
$g: \mathbb R \to \mathbb R$ is to further divide the sum by the
sample size, to get the sample mean , i.e. $g(f(x_1, \dots, x_n)) =
\sum_i x_i/n$.
Is $g(f(x_1, \dots, x_n))$ a composition of the two mappings $f$ and
$g$?  
I think that in a  composition of two mappings, the outer mapping 
only acts on the codomain of the inner mapping, and thus shouldn't
know the input to the inner mapping. In the example, $g$ should not
know  $n$. So it doesn't make sense to  compose $f$ and $g$. 
A revision would be $f: \cup_{n \in \mathbb N} \mathbb R^n \to
\mathbb  R \times \mathbb N$ with $f(x_1, \dots, x_n) =  [\sum_i
x_i, n]^T$, and $g: \mathbb  R \times \mathbb N \to \mathbb R$ with
$g(x,n) = x/n$. Only then the composition of $f$ and $g$ would make
sense to me. What would you think?

*The question comes from statistics, where $f$ is a "statistic" which
takes in a sample of size $n$, and $n$ can vary in $\mathbb N$, and
$g$ is a transform on the statistic. To see more of my specific
question, please refer to
https://stats.stackexchange.com/questions/114240/can-the-measurable-mapping-in-the-definition-of-complete-statistics-depend-on-sa.
Here at math.se, I ask a more general question for general math. In
the link to stats.se, I asked a specific question in
statistics. I understand that the answers to the two may be related and different.
Thanks.
 A: There are a couple of problems with your definitions. First, your definition of the domain of $f$ is missing. If you mean the domain to be the set of $\infty$-tuples in which only finitely many entries are nonzero, you should say so. In the way you wrote your domain, I would have asked you what your inclusion of $\mathbb R^n$ into $\mathbb R^{n+1}$ was. I did assume that your union was not a disjoint union, but involved inclusions of smaller spaces into largers.
As you describe $g$, it is not a function, since its value depends on the particular $\mathbb R^n$ you want to consider the argument to lie in. You could make a well-defined $g$ that counted up the number of nonzero entries in your $\infty$-tuple, and divided by that number, and this would certainly be well-defined, but neither linear nor continuous.
I’m having trouble understanding your revision, too, again for the reason that you don’t know which $\mathbb R^n$ an element of your “union” lies in. 
A: The form of expression ("access the arguments of the inner mapping") suggests to me that you're bringing a programmer's perspective to this subject.  Your formulation in #1 is the correct idea, but you should probably introduce two auxiliary functions s and d as follows: for any x in the disjoint union, d(x) is the dimension of the unique Cartesian space containing x and s(x) is the sum of the components of x.  Then your f(x) is simply (s(x),d(x)) and your g computes the desired ratio from any pair (r,n) of a real r and a natural number n.  That's too tediously pedantic for normal mathematical discourse, but comfy for functional programmers ;-)
