This is essentially a follow up motivated by this answer to my question about the gauge transformation interpretation of identity types.
A field $$\psi:\mathcal M\to\mathbb C^n$$ is a section of the $\mathbb C^n$-bundle over the spacetime manifold $\mathcal M$. We have a local gauge transformations $$\psi(x)\mapsto \psi'(x):=U(x)\,\psi(x)\ :\ (\mathcal M\to \mathbb C^n)\to(\mathcal M\to \mathbb C^n).$$
Now consider a language with type polymorphism and the class $M$ of all it's types whose elements can be put into a list. Let $\Psi$ be the polymorphic function which, for every type $X\in M$, maps an $X$-list to an integer, namely its length. For example, using Haskell syntax, if $X=\mathrm{Bool}$, then $\Psi_\mathrm{Bool}\left([\mathrm{True},\mathrm{True},\mathrm{False}]\right) = 3$. In System F notation, we have
$$\Psi:\forall X.\left([X]\to\mathrm{Int}\right).$$
The gauge transformations should correspond to maps
$$u\ :\ \forall X.\left([X]\to\mathrm{Int}\right)\ \longrightarrow\ \forall X.\left([X]\to\mathrm{Int}\right).$$
I could come up with some $u$'s, for example mapping the length function $\Psi$ to a map $\Psi':=u\,\Psi$ which instead returns 42 times the length of a list. But that would be, in physics terms, a global gauge transformation because it's not sensitive to the type $X$. I think, given that the only invariant of a finite dimensional vector space is its cardinality, it shouldn't be possible to construct a local transformation in this case. What would be a hands-on example for a local gauge transformation in this sense?
Moreover, I wanted to draw an everyday life parallel to identity types. Well first there is the minor obstacle that the above transformation can't be given by an expression in most language, as types are usually not first class objects. I guess this design choice is made because otherwise type inference would be spoiled. In homotopy type theory you have realization of "types are terms too" (via n-categories?) and then it's possible. But in any case, I still can't quite pin down the specification when a type is an identity type. I understand "identity" for homotopy equivalent spaces and gauge invariant Lagrangians, but are there non-geometric structures, specifically programming relevant ones, which behave identical before and after the transformation?
edit: I now made two visualization of the example here and then:
The question then is what a sensible gauge of the section in the second pic would be. (I also made two more pictures going beyond what's asked: natural transformations and monads as in Haskell.)
Btw., I know that HoTT does implement dependent types, not "just" parametrically polymorphic ones, but that should not be an obstacle.