A Trace Semantics for System F Parametric Polymorphism
Abstract
We present a trace model for Strachey parametric polymorphism. The model is built using operational nominal game semantics and captures parametricity by using names. It is used here to prove an operational version of a conjecture of Abadi, Cardelli, Curien and Plotkin which states that Strachey equivalence implies Reynolds equivalence in System F.
1 Introduction
Parametricity was first introduced by Strachey [22] as a way to characterise the behaviour of polymorphic programs as being uniform with respect to the type of the arguments provided. He opposed this notion to adhoc polymorphism, where a function can produce arbitrarily different outputs when provided inputs of different types (for example an integer and a boolean). To formalise this notion of parametricity, Reynolds introduced relational parametricity [21]. It is defined using an equivalence on programs, that we call Reynolds equivalence and is a generalisation of logical relations to System F. This equivalence uses arbitrary relations over pairs of types to relate polymorphic programs. So a parametric program that takes related arguments as input will produce related results. Reynolds parametricity has been developed into a fundamental theory for studying polymorphic programs [1, 20, 23].
Following results of Mitchell on PERmodels of polymorphism [18], Abadi, Cardelli, Curien and Plotkin [1, 20] introduced another, more intentional notion of equivalence, called Strachey equivalence. Two terms of System F are Strachey equivalent whenever, by removing all their type annotations, we obtain two \(\beta \eta \)equivalent untyped terms. The authors conjectured that Strachey equivalence implies Reynolds equivalence (the converse being easily shown to be false).
In this paper we examine a notion of Reynolds equivalence based on operational logical relations, and prove that, for this notion, the conjecture holds. To do so, we introduce a trace model for System F based on operational nominal game semantics [12, 14]. Terms in our model are denoted as sets of traces, generated by a labelled transition system, which represent interactions with arbitrary term contexts. In order to abstract away type information from inputs to polymorphic functions, our semantics uses names to model such inputs. The idea is the following: since names have no internal structure, the function has no choice but to act “the same way” on such inputs, i.e. be parametric. Our trace model yields a third notion of equivalence: trace equivalence (i.e. equality of sets of traces). Then, the result is proven by showing that trace equivalence is included in (operational) Reynolds equivalence, while it includes Strachey equivalence.
The traces in our model are formed of moves, which represent interactions between the modelled term (the Player) and its context (the Opponent): either of Player or Opponent can interrogate the terms provided by the other one, or respond to a previous such interrogation. These moves are called questions and answers respectively. Names enter the scene when calling terms which are of polymorphic type, in which case the calling party would replace the actual argument type \(\theta \) with a type name \(\alpha \), and record locally the correspondence between \(\alpha \) and \(\theta \). Another use of names in our model is for representing terms that are passed around as arguments to questions. These are called computation names, and are typed according to the term they each represent.
2 Definition of System F and Parametricity

\(\mathbf {Bool}=\forall X.\ X\rightarrow X\rightarrow X\), \(\mathbf {true}=\varLambda X.\lambda x^X\!.\lambda y^X\!.x\) and \(\mathbf {false}=\varLambda X.\lambda x^X\!.\lambda y^X\!.y\),

\(\mathbf {Unit}=\forall X.\ X\rightarrow X\) and \(\mathbf {id}=\varLambda X.\lambda x^X.x\).
Definition 1
The following result is standard [21].
Theorem 2
(Fundamental Property). If \(\varDelta ;\varGamma \vdash M:\tau \) then \(\varDelta ;\varGamma \vdash M \simeq _{log} M : \theta \).
Remark 3
Note that our definition of Reynolds equivalence does not coincide with either of the definitions given in [1, 20]: therein, parametricity is defined using relational logics (and accompanying proof systems), whereas here we use quantification over concrete relations over closed terms.
Definition 4
Given terms \(\varDelta ;\varGamma \vdash M_1,M_2 : \theta \), we say that they are Strachey equivalent if \(\mathbf {erase}(M_1) =_{\beta \eta }\mathbf {erase}(M_2)\).
It was conjectured in [1, 20] that Reynolds equivalence includes Strachey equivalence. We prove this holds for the version of Reynolds equivalence given in Definition 1.
Theorem 5
Any two Strachey equivalent terms are also Reynolds equivalent.
It is interesting to think why a direct approach would not work in order to prove this conjecture. Given Strachey equivalent terms \(M_1,M_2\) of type \(\mathbf {Bool}\), suppose we want to prove them Reynolds equivalent. We therefore take \((\theta _1,\theta _2,R) \in \mathrm {Rel}\), \((N_{1,1},N_{2,1}) \in R\), and \((N_{1,2},N_{2,2}) \in R\), and aim to prove that \((M_1 \theta _1 N_{1,1} N_{1,2}, M_2 \theta _2 N_{2,1} N_{2,2}) \in R\). Ideally, we would like to prove that there exists \(j \in \{1,2\}\) s.t. for all \(i \in \{1,2\}\), \(M_i \theta _i N_{i,1} N_{i,2} =_{\beta \eta }N_{i,j}\), but that seems overly optimistic. A first trick is to use Theorem 2, to get that \(M_2\) is related with itself. Thus, we get that \((M_2 \theta _1N_{1,1} N_{1,2}, M_2 \theta _2 N_{2,1} N_{2,2}) \in R\), and it would suffice to prove \(M_1 \theta _1N_{1,1} N_{1,2} =_{\beta \eta }M_2 \theta _1N_{1,1} N_{1,2}\) to conclude. However, our hypothesis is simply that \(\mathbf {erase}(M_1) =_{\beta \eta }\mathbf {erase}(M_2)\).
A possible solution to the above could be to \(\beta \)reduce both \(M_i \theta _1N_{1,1} N_{1,2}\), hoping that the distinction between the two terms will vanish. Our trace semantics provides a way to model the interaction between such a term \(M_i\) and a context \(\bullet \, \theta _jN_{j,1} N_{j,2}\), and to deduce properties about the normal form reached by their application via head reduction.
3 A Nominal Trace Semantics for System F
In this section we introduce a trace semantics for open terms which will be our main vehicle of study for System F. The terms in our semantics will be allowed to contain special constants representing any term that could fill in their open variables (these be term or type variables). The use of names can be seen as a nominal approach to parametricity: parametric types and values are represented in our semantics by names, without internal structure. Thus, e.g. a parametric function is going to behave “the same way” for any input, since the latter will be nothing but a name.
We will use the notation \(\hat{M},\hat{N}\), and variants, to refer jointly to namey terms and namey types. Namey terms are typed with additional typing hypotheses for the added constants. These typings are made explicit in the trace model. By abuse of terminology, we will drop the adjective “namey” and refer to the above simply as “terms” and “types”. Formally speaking, namey terms and types form nominal sets (cf. Definition 8).
Note 6
(what do c’s and \(\alpha \)’s represent?). A computation name c represents a term that can replace the open variables of a term M. That is, in order to examine the semantics of \(\lambda x^\theta {.}M\), we will look instead at \(M\{c/x\}\) where c a computation name of appropriate type. Type names \(\alpha \) have a similar purpose, for types.
Our trace semantics is built on top of head reduction, which is reminded next. Moreover, we shall be using types in extended form, which determines the number and types of arguments needed in order to fully apply a term of a given type.
Definition 7
We let \(\rightarrow ^{*}\) be the reflexivetransitive closure of \(\rightarrow \). It is a standard result that \(\rightarrow ^{*}\) preserves typing and (strongly) normalises to head normal forms.
We finally introduce some infrastructure for working with objects with names.
Definition 8
We call a permutation \(\pi :\mathsf {N}\rightarrow \mathsf {N}\) finite if the set \(\{a~~\pi (a)\ne a\}\) is finite, and componentpreserving if, for all \(a\in \mathsf {N}\), \(a\in \mathsf {TN}\) iff \(\pi (a)\in \mathsf {TN}\).
A nominal set [7] is a pair \((Z,*)\) of a set Z along with an action \((*)\) from the set of finite componentpreserving computations of \(\mathsf {N}\) on the set Z. For each \(z\in Z\), the set of names featuring in z form its support, written \(\nu (z)\), which we stipulate to be finite.
In the sequel, when constructing objects with names (such as moves or traces) we shall implicitly assume that these form nominal sets, where the permutation action is defined by taking \(\pi *z\) to be the result of applying \(\pi \) to each name in z.
3.1 Trace Semantics Preview
Before formally presenting the trace model, we look at some examples informally, postponing the full details for the next section. Headreduction brings terms into head normal form. The trace semantics allows us to further ‘reduce’ terms of the form \(E[c\hat{M}_1\cdots \hat{M}_n]\), where c is some computation name. For such a term, following the game semantics approach [3, 11], our model will issue a move interrogating the computation c on arguments \(\hat{M}_i\), and putting E on top of an evaluation stack, denoted \(\mathcal {E}\). The move is effectively a call to c, and \(\mathcal {E}\) functions as a call stack which registers the calls that have been made and are still pending. This will effectively lead to a labelled transition system in which labels are moves issued by two parties: a Player (P), representing the modelled term, and an Opponent (O) representing its enclosing term context.

Player questions \(\bar{c}( a_1,...,a_n )\) (also Pquestions),

Opponent questions \(c ( a_1,...,a_n )\) (also Oquestions),

POanswers Open image in new window , and OPanswers Open image in new window .
Given a question move as above, we let its core name be c. We distinguish a computation name \(c_\mathrm{in}\in \mathsf {CN}\), and call questions with core name \(c_\mathrm{in}\) initial. We define a trace T to be a finite sequence of moves. Traces will be restricted to legal ones in Definition 12.
Example 9

\(c_\mathrm{in}\) is the computation name assigned (by convention) to the term being evaluated (in this case, \(\mathbf {id}\));

\(\alpha ,c\) are names abstracting the actual type and term arguments which \(\mathbf {id}\) is called on. It is assumed that c is of type \(\alpha \).
Note 10
(what are Open image in new window and Open image in new window ?). As System F base types are type variables, there is no real need for answer moves: a type X has no return values. For example, in the game models of Hughes [9] and Laird [15], answer moves were effectively suppressed (either explicitly, or by allowing moves \(c(\cdots )\) to function as answers). Here, to give the semantics an operational flavour, we introduce instead explicit ‘dummy’ answers \(\mathsf {OK}\).
Example 11
3.2 Definition of the LTS
We now proceed with the formal definition of the trace semantics. We start off with a series of definitions setting the conditions for a trace to be legal.

m is a question with core name c and \(m'\) introduces c, or

m is an answer which answers \(m'\) (and \(m'\) is a question).
Answering of questions is defined as follows. Each answer (occurrence) m answers the pair of question moves \((m_1,m_2)\) containing the last two question moves in T which are before m and have not been answered yet.
We can now define legality conditions for traces. Below, for \(A\in \{O,P\}\), we say that a move is Astarting if it is an Aquestion or an \(AA^\bot \)answer (where \(O^\bot =P\) and \(P^\bot =O\)). Similarly, a move is Aending if it is either an Aquestion or an \(A^\bot A\)answer.
Definition 12
 1.
Aending moves can only be followed by \(A^\bot \)starting moves;
 2.
all moves in T are justified, apart from the first move which must be initial;
 3.
apart from \(c_\mathrm{in}\), every name of T is introduced exactly once in it;
 4.
for each Aquestion with core name \(c\ne c_\mathrm{in}\), we have \(c\in A^\bot (T)\);
 5.
if an \(A{A}^\bot \)answer answers \((\!m,m')\) then these are A and \(A^\bot \)questions respectively.
The conditions above can be given names (suggesting their purpose) as follows: 1. alternation, 2. justification, 3. wellintroduction, 4. wellcalling, 5. wellanswering.
Each trace T has a complement, which we denote \(T^\bot \) and is obtained from T by switching \(O{\slash }P\) in all of its moves (i.e. each \(c ( \vec a )\) becomes \(\bar{c}( \vec a )\), Open image in new window becomes Open image in new window , etc). T is legal iff \(T^\bot \) is.

\(\gamma \) assigns termtype pairs to computation names, and type\(\mathcal {U}\) pairs to type names,

\(\phi \) assigns types to computation names, and \(\mathcal {U}\) to type names.

\(\vec a\) is a sequence \((a_1,...,a_n)\) of names (abstracting each of the arguments \(\hat{M}_i\)),

\(\gamma \) is a map as above, with domain \(\{a_1,...,a_n\}\),

\(\beta \) is the result type one gets after applying each \(a_i\) for each \(\tau _i\).
The operator is formally defined next. In the same definition we introduce the semantics of types, \([\![\theta ]\!]\), as sets of triples of the form \((\vec a,\phi ,\beta )\), which represent all possible inputoutput name tuples \((\vec a,\beta )\) that are allowed for \(\theta \), including their typing \(\phi \).
Definition 13
Both \(\phi \) and \(\gamma \) are finite partial functions whose domains are sets of names. For such maps, the extension notation we used e.g. in \(\phi \cdot [c\mapsto z]\) (for appropriate z) means fresh extension: \(\phi \cdot [c\mapsto z]=\phi \cup \{(c,z)\}\) and given that \(c\notin \mathrm {dom}(\phi )\). This notation is extended to whole maps: e.g. \(\phi \cdot \phi '=\phi \cup \phi '\) and given that \(\mathrm {dom}(\phi )\cap \mathrm {dom}(\phi ')=\varnothing \). Moreover, for each map \(\gamma \) we write \(\mathsf {fst}(\gamma )\) for its first projection: \(\mathsf {fst}(\gamma )= \{(a,\hat{M})~~\gamma (a)=(\hat{M},\_)\}\). Similarly, second projection is given by: \(\mathsf {snd}(\gamma )= \{(a,Z)~~\gamma (a)=(\_,Z)\}\).
Definition 14
A configuration is a triple \(\langle \mathcal {E},\gamma ,\phi \rangle \) where \(\mathcal {E}\) is an evaluation stack and \(\gamma \) and \(\phi \) are as above. The reduction rules of the LTS are given in Fig. 3. We write \(\mathsf {Tr}(C)\) for the set of traces generated by a configuration C.
A configuration is active (resp. passive) if its evaluation stack is so. An active configuration stands for a term being computed and it may only produce Pmoves. A passive configuration, on the other hand, stands for a scenario where O is next to play. Moreover, the map \(\phi \) in a configuration contains information on the Onames that have been played, i.e. \(\mathrm {dom}(\phi )\) contains Onames, while \(\mathrm {dom}(\gamma )\) contains Pnames.
To better grasp Fig. 3 let us consider an initial configuration \(\langle \lozenge ,[c_\mathrm{in}\mapsto ({M},{\theta })],\varepsilon \rangle \) and look at its traces, for some closed term M (so no need for \(\widetilde{M},\widetilde{\theta }\)) with empty support.

At the beginning, the only rule that can be applied is (OQ\(_0\)), whereby O interrogates the term M by issuing a move \(c_\mathrm{in} ( \vec a )\). The names \(\vec a\) are selected from \([\![\theta ]\!]\) and represent arguments that O fully applies the term M on. Since \(\theta \) has empty support, its extended form is of the shape \((\tau _1,...,\tau _n,X)\) with \(X\) bound by one of the \(\tau _i\)’s. Consequently, when the names \(a_1,...,a_n\) are applied for \(\tau _1,...,\tau _n\), the variable \(X\) will be replaced by some type name \(\alpha \). The rule makes this explicit, by requiring that \((\vec a,\phi ',\alpha )\in [\![\theta ]\!]\). Thus, writing \(\phi _0\) instead of \(\phi '\) and setting \(\gamma _0=[c_\mathrm{in}\mapsto ({M},{\theta })]\), the transition brings us to a configuration \(\langle [(M\vec a,\alpha )],\gamma _0,\phi _0\rangle \), where \(\mathrm {dom}(\phi _0)=\{a_1,...,a_n\}\).

At this point, the term \(M\vec a\) can be reduced using head reduction and brought to head normal form. Applying the (INT) rule we reach some \(\langle [(E[c\hat{M}_1\cdots \hat{M}_k],\alpha )],\gamma _0,\phi _0\rangle \).

We next interrogate the computation name c. The latter must have come from the \(a_1,...,a_n\) that were applied to M, hence is an Oname. To interrogate it, P plays a question \(\bar{c}( \vec a' )\), using the (PQ) rule and assuming \((\vec a',\gamma ',\alpha ')\in \mathsf {AVal}(((\hat{M}_1,\tau _1'),...,(\hat{M}_k,\tau _k'),\xi ))\), \(\phi _0(c)=\theta '\), \(\mathrm {ext}(\theta ')=(\tau _1',...,\tau _k',\xi )\). This leads to Open image in new window (\(\gamma _1=\gamma _0\cdot \gamma '\)).

We are now at a passive configuration, where E has been stored on the stack and O is required to produce a response of type \(\alpha '\). By definition of \(\mathsf {AVal}\), either \(\alpha '=\alpha \) or \(\alpha '\) is in \(a_1',...,a_k'\) and hence belongs to P. In the latter case, O can only produce such a response by calling back P, using rule (OQ), playing an Oquestion and adding a new term on the evaluation stack. In the former case, O would directly respond with a hnf of type \(\alpha \), say N. But, since Open image in new window and therefore \(E=\bullet \), P would simply reply back playing N again. To avoid this copycat of hnf’s, we simply play an OPanswer and remove the top of the evaluation stack – this is what the (OA) rule achieves.
Example 15
In Fig. 4 we include example traces for terms \(M_1,M_2:\mathbf {Unit}\rightarrow \mathbf {Unit}\) (taken from [1], Instance 3.25) and for the Church numerals \(M_k:\mathbf {Nat}\). The former pair is an instance of Theorem 21 – Strachey equivalence implies trace equivalence.

a term configuration, if \(\mathcal {E}=\lozenge \) or the bottom element of \(\mathcal {E}\) has type \(\alpha \) or Open image in new window ;

a context configuration, if the bottom of \(\mathcal {E}\) has type \(\theta \) or Open image in new window , and \(\theta \) is a closed with empty support.
Each reduction sequence in the LTS can only contain either term or context configurations. In our discussion above and in Example 15 we examine the semantics of terms, and therefore use term configurations. In later sections, when we shall start looking at the semantics of contexts, we will be using context configurations as well.
While we have not defined leaves for our LTS, there is a natural notion of a trace being “completed”. In particular, we call a trace T complete if all its questions have been answered. We write \(\mathsf {CTr}(C)\) for the set of complete traces generated from C. Term and context configurations can both produce complete traces. Given a term configuration C and a complete trace T, we write \(C\Downarrow _{T}\) if \(C\xrightarrow {T}C'\) and \(C'\) has an empty evaluation stack. On the other hand, given a context configuration C, a complete trace T and a value v, we write \(C\Downarrow _{T,v}\) if \(C\xrightarrow {T}C'\) and \(C'\) has an evaluation stack with a single element \((v,\theta )\).
Lemma 16
Given a term configuration C and \(T \in \mathsf {Tr}(C)\), then T is complete iff \(C \Downarrow _{T}\).
We conclude this section by looking at some restrictions characterising actual configurations. We first extend \(\mathsf {fst}\) to evaluation stacks by: \(\mathsf {fst}(\lozenge )=\lozenge \) and \(\mathsf {fst}((Z,\_)\,{:}{:}\,\mathcal {E})=Z\,{:}{:}\,\mathsf {fst}(\mathcal {E})\).
Definition 17

\(\mathrm {dom}(\gamma ) \cap \mathrm {dom}(\phi ) = \varnothing \) and \(\nu (\mathsf {fst}(\mathcal {E})) \cup \nu ({\mathrm {cod}(\mathsf {fst}(\gamma ))}) \subseteq \mathrm {dom}(\phi )\);

for all \(c \in \mathrm {dom}(\gamma ) \cap \mathsf {CN}\), given \(\gamma (c)=(M,\theta )\), we have \(\varDelta _{\phi }; \varGamma _{\phi ,\gamma } \vdash M:\theta \{\gamma _v\}\);

if the top of \(\mathcal {E}\) is \((M,\theta )\), then \(\varDelta _{\phi }; \varGamma _{\phi ,\gamma } \vdash M:\widetilde{\theta }\) with either \(\theta = \alpha \in \mathrm {dom}(\gamma )\) and \(\gamma (\alpha ) = (\widetilde{\theta },\mathcal {U})\), or \(\theta = \alpha \in \mathrm {dom}(\phi )\) and \(\widetilde{\theta } = \theta \), or \(\theta = \widetilde{\theta }\) is a closed type with empty support and \(\mathcal {E}=[(M,\theta )]\);

If \(\mathcal {E}= (M,\alpha _1)\,{:}{:}\,(E,\alpha _2 \rightsquigarrow \theta )\,{:}{:}\,\mathcal {E}'\), either \(\alpha _1 =\alpha _2\) or \(\alpha _1 \in \mathrm {dom}(\phi )\);

for all \((E,\alpha \rightsquigarrow \theta )\) in \(\mathcal {E}\) with \(\alpha \in \mathrm {dom}(\gamma )\), \(\varDelta _{\phi }; \varGamma _{\phi ,\gamma }, \vdash E:\gamma _v(\alpha ) \rightsquigarrow \theta \), and either \(\theta = \alpha \in \mathrm {dom}(\phi )\) or \(\theta \) is a closed type with empty support, and \((E,\alpha \rightsquigarrow \theta )\) is at the bottom of \(\mathcal {E}\);

for all \((E,\alpha \rightsquigarrow \theta )\) in \(\mathcal {E}\) with \(\alpha \in \mathrm {dom}(\phi )\), we have \(\theta = \alpha \) and \(E = \bullet \);
Lemma 18
If C is a legal configuration and \(C \xrightarrow {m} C'\) then \(C'\) is a legal configuration.
4 Parametricity in the Trace Model, and Proof of Theorem 5
We next examine the relationship between trace equivalence and the notions of Reynolds and Strachey equivalence. We prove that Strachey equivalence is included in trace equivalence (Theorem 21), which in turn is included in Reynolds equivalence (Theorem 28).
4.1 From Strachey to Trace Equivalence
Definition 19

for all \(c \in \mathrm {dom}(\gamma _1)\), if \(\gamma _i(c)=(M_i,\theta _i)\) then \(\theta _1 = \theta _2\) and \(\mathbf {erase}(M_1)\! =_{\beta \eta }\!\mathbf {erase}(M_2)\);

if \((Z_i,\alpha _i)\) is the jth element of \(\mathcal {E}_i\), then \(\alpha _1 = \alpha _2\) and \(\mathbf {erase}(Z_1) =_{\beta \eta }\mathbf {erase}(Z_2)\);
The first inclusion can then be proven as follows.
Lemma 20
Given two Stracheyequivalent legal configurations \(C_1,C_2\), if \(C_1 \xrightarrow {m} C'_1\) for some \(m,C_1'\) then there is \(C_2 \xrightarrow {m} C'_2\) such that \(C'_1\) and \(C'_2\) are Stracheyequivalent.
Theorem 21
For all Stracheyequivalent \(\varDelta ,\varGamma \vdash M_1,M_2 : \theta \), we have \([\![M_1 ]\!] = [\![M_2 ]\!]\).
Proof
Taking \(T \in [\![\varDelta ; \varGamma \vdash M_1 : \theta ]\!]\), we prove that \(T \in [\![\varDelta ; \varGamma \vdash M_2 : \theta ]\!]\) by induction on the length of T, using the previous lemma. \(\square \)
4.2 Composite LTS
We let a composite configuration be a tuple \(\langle \mathcal {E}_P,\mathcal {E}_O,\gamma _P,\gamma _O\rangle \), where \(\gamma _P\) and \(\gamma _O\) are maps \(\gamma \) as above, \(\mathcal {E}_P\) is a term evaluation stack, and \(\mathcal {E}_O\) is a context evaluation stack. These configurations represent the interaction between a term and a context. The termpart in the interaction is played by \(\mathcal {E}_P\) and \(\gamma _P\), while the contextpart by \(\mathcal {E}_O\) and \(\gamma _O\). As with ordinary configurations, we define an LTS for composite ones in Fig. 5. Given a composite configuration C, a trace T and a value v (hnf with empty support) we write \(C \Downarrow _{T,v}\) when \(C \xrightarrow {T} \langle \lozenge ,[(v,\theta )],\gamma _P,\gamma _O\rangle \).
Composite configurations allow us to compose a term and a context semantically: we essentially play the traces of one against the other. Another way to obtain a composite semantics is to work syntactically, i.e. by composing configurations and then executing the resulting term. This is defined next.
Definition 22
We now relate the reduction of a composite configuration with the head reduction of the merge of its two evaluation stacks. First, taking the two environments \(\gamma _P,\gamma _O\) of a legal composite configuration, we compute their closure \((\gamma _P \cdot \gamma _O)^{*}\) as follows. Setting \(\gamma ^0=\mathsf {fst}(\gamma _P \cdot \gamma _O)\), and \(\gamma ^i = \{(a,\hat{M}\{\gamma \}) ~~(a,\hat{M}) \in \gamma ^{i1}\}\) \((i > 0)\), there is an integer n such that \(\nu ({\mathrm {cod}(\gamma ^n)}) = \varnothing \). We write \((\gamma _P \cdot \gamma _O)^{*}\) for the environment defined as \(\gamma ^n\), for the least n satisfying this latter condition.
Theorem 23
Given a legal composite configuration \(C=\langle \mathcal {E}_P,\mathcal {E}_O,\gamma _P,\gamma _O\rangle \), then \(C \Downarrow _{T,v}\) iff \((\mathcal {E}_P  \mathcal {E}_O)\{(\gamma _{P}\cdot \gamma _{O})^{*}\} \rightarrow ^{*} v\).
Finally, we relate the LTS’s for composite configurations and ordinary configurations (Theorem 26). Combined with Theorem 23, this gives us a correlation between the traces of two compatible configurations and the head reduction we obtain once we merge their evaluation stacks.
Definition 24
Given legal configurations \(C_P = \langle \mathcal {E}_P,\gamma _P,\phi _P\rangle \) and \(C_O = \langle \mathcal {E}_O,\gamma _O,\phi _O\rangle \), we say that they are compatible when \(\mathcal {E}_P,\mathcal {E}_O\) are compatible, \(\mathsf {snd}(\gamma _{P}) = \phi _O\) and \(\mathsf {snd}(\gamma _{O}) = \phi _P\). For each pair \((C_P,C_O)\) of compatible configurations, we define their merge \(C_P \mathbin {\!{\wedge }\!\!\!{\wedge }\!} C_O\) as the composite configuration \(\langle \mathcal {E}_P,\mathcal {E}_O,\gamma _P,\gamma _O\rangle \).
Lemma 25
Taking \((C_P,C_O)\) a pair of compatible configurations, \(C_P \mathbin {\!{\wedge }\!\!\!{\wedge }\!} C_O \Downarrow _{T,v}\) iff \(C_P \Downarrow _{T}\) and \(C_O \Downarrow _{T^{\bot },v}\).
Theorem 26
Given \(C_{P,1},C_{P,2},C_O\) such that \(C_{P,1},C_O\) and \(C_{P,2},C_O\) are pairwise compatible and \(\mathsf {Tr}(C_{P,1}) = \mathsf {Tr}(C_{P,2})\), if \(C_{P,1} \mathbin {\!{\wedge }\!\!\!{\wedge }\!} C_{O} \Downarrow _{T,v}\), then \(C_{P,2} \mathbin {\!{\wedge }\!\!\!{\wedge }\!} C_{O} \Downarrow _{T,v}\).
Proof
From Lemma 25 we get \(C_{P,1} \Downarrow _{T}\) and \(C_{O} \Downarrow _{T^{\bot },v}\). Thus, \(T \in \mathsf {Tr}(C_{P,1})\) and hence \(T \in \mathsf {Tr}(C_{P,2})\). Lemma 16 then yields \(C_{P,2} \Downarrow _{T}\) and, from Lemma 25, \(C_{P,2} \mathbin {\!{\wedge }\!\!\!{\wedge }\!} C_{O} \Downarrow _{T,v}\). \(\square \)
4.3 Proof of Theorem 5
Theorem 5 follows from Theorems 21 and 28. Theorem 28, which is proved below, shows that any trace equivalent terms are also Reynolds equivalent. This is achieved as follows. In the previous section we saw how to relate reductions of termsincontext to the semantics of terms and contexts. Given terms \(M_1,M_2\) which are trace equivalent, and fully applying them to related arguments, we obtain head reductions to values. These reductions can be decomposed into LTS reductions producing corresponding traces, for the terms and their argument terms (which form contexts). But, since the terms are trace equivalent, \(M_2\) can simulate the behaviour of \(M_1\) in the context of \(M_1\), and that allows us to show that the two composites reduce to the same value.
Lemma 27
\((M_1,M_2) \in \mathcal {R}[\![\theta ]\!]_{\delta }\) iff for all \(((\hat{N}^{1}_1,\hat{N}^{1}_2),\ldots ,(\hat{N}^{n}_1,\hat{N}^{n}_2),R) \in \mathcal {R}[\![\mathrm {ext}(\theta ) ]\!]_{\delta }\), \((M_1 \hat{N}^{1}_1 \cdots \hat{N}^{n}_1,M_2 \hat{N}^{1}_2 \cdots \hat{N}^{n}_2) \in R\).
Theorem 28
For all trace equivalent \(\varDelta ;\varGamma \vdash M_1,M_2:\theta \), we have that \({M_1}\simeq _{log}~{M_2}\).
Proof
Taking \(\delta \in \mathcal {R}[\![\varDelta ]\!]\) and \((\eta _1,\eta _2) \in \mathcal {R}[\![\varGamma ]\!]_{\delta }\), we show \((M_1\{\eta _1\}\{\delta _1\}, M_2\{\eta _2\}\{\delta _2\}) \in \mathcal {R}[\![\theta ]\!]_{\delta }\). Using Lemma 27, we take \(((\hat{N}^{1}_1,\hat{N}^{1}_2),\ldots ,(\hat{N}^{n}_1,\hat{N}^{n}_2),R) \in \mathcal {R}[\![\mathrm {ext}(\theta ) ]\!]_{\delta }\), and prove that \((M_1\{\eta _1\}\{\delta _1\} \hat{N}^{1}_1 \cdots \hat{N}^{n}_1, M_2\{\eta _2\}\{\delta _2\} \hat{N}^{1}_2 \cdots \hat{N}^{n}_2) \in R\).
For each \(i \in \{1,2\}\), there exists a value \(v_i\) s.t. \(M_i\{\eta _i\}\{\delta _i\} \hat{N}^{1}_i \cdots \hat{N}^{n}_i \rightarrow ^{*} v_{i}\). Using the closure of R w.r.t. \(=_{\beta \eta }\), it suffices to show that \((v_{1},v_{2}) \in R\). Suppose \(\varDelta = X_1,\ldots ,X_k\) and \(\varGamma = x_1:\theta _1,\ldots ,x_m:\theta _m\). We write \(C_{P_i}\) for the configuration \(\langle \varDelta ; \varGamma \vdash M_i : \theta \rangle \), and \(C_{O,i}\) for the configuration \(\langle c_\mathrm{in}\delta _i(X_1) \cdots \delta _i(X_k) \eta _i(x_1) \cdots \eta _i(x_m) \hat{N}^{1}_i \cdots \hat{N}^{n}_i,\varepsilon ,[c_\mathrm{in}\mapsto \widetilde{\theta }]\rangle \), where \(\widetilde{\theta } =\forall X_1. \ldots \forall X_n.\theta _1 \rightarrow \cdots \rightarrow \theta _m \rightarrow \theta \).
From Theorem 23, for each \(i \in \{1,2\}\) there is a trace \(T_{i}\) such that \(C_{P,i} \mathbin {\!{\wedge }\!\!\!{\wedge }\!} C_{O,i} \Downarrow _{T_{i},v_{i}}\). \(M_1,M_2\) being trace equivalent, we have that \(\mathsf {Tr}(C_{P,1}) = \mathsf {Tr}(C_{P,2})\). So from Theorem 26, we get that \(C_{P,2} \mathbin {\!{\wedge }\!\!\!{\wedge }\!} C_{O,1} \Downarrow _{T_{1},v_1}\), and from Theorem 23 that \(M_2\{\eta _1\}\{\delta _1\} \hat{N}^{1}_1 \cdots \hat{N}^{n}_1 \rightarrow ^{*} v_1\). Finally, from Theorem 2, we get that \((M_2\{\eta _1\}\{\delta _1\} \hat{N}^{1}_1 \cdots \hat{N}^{n}_1, M_2\{\eta _2\}\{\delta _2\} \hat{N}^{1}_2 \cdots \hat{N}^{n}_2) \in R\). Thus, using the closure of R w.r.t. \(=_{\beta \eta }\), we have that \((v_{1},v_{2}) \in R\). \(\square \)
5 Related and Future Work
The literature on parametric polymorphism is vast; here we look at the works closest to ours, which come from the game semantics area. The first game model for System F was introduced by Hughes [9, 10]. The model is intentional, in the sense that it is fully complete for \(\beta \eta \)equivalence. Starting from that model, de Lataillade [5, 6] characterised parametricity categorically via the notion of dinaturality [4]. In [2], Abramsky and Jagadeesan developed a model for System F to characterise genericity, as introduced by Longo et al. [17]. A type \(\theta \) is said to be generic when two terms \(M_1,M_2\) of type \(\forall X.\theta '\) are equivalent just if \(M_1 \theta \) and \(M_2 \theta \) are equivalent. Their model contains several generic types. More recently, Laird [15] has introduced a game model for System F augmented with mutable variables. His model is closer to ours than the previous ones, and in particular his notion of copycat links can be seen as connected to the use of names for parametricity.
In all of the above models the denotation of terms is built compositionally by induction on the structure of the term. In a different line of work, closer in spirit to our model, Lassen and Levy [16] have introduced normal form bisimulations for a language with parametric polymorphism. These bisimulations are defined on LTSs whose definition has similarities with ours. However, the model is for a CPSstyle language which has not only polymorphic but also recursive types. Finally, our own model for a higherorder polymorphic language with general references [13] can be seen as a direct precursor to this work, albeit in a very different setting (callbyvalue, with references).
Further on, we would like to study the existence of generic types in our model, as well as its dinaturality properties. We would moreover like to examine coarser notions of trace equivalence that bring us closer to Reynolds polymorphism. Finally, we would like to see if the trace model can be used to prove the original conjecture of [1, 20]. While this seems plausible in principle, proving equivalences using definable logical relations requires additional tools, such as restrictions on the LTS, to avoid circular reasoning.
Notes
Acknowledgement
Authors supported by the LABEX MILYON (ANR10LABX0070) of Université de Lyon, and the EPSRC (EP/P004172/1) respectively.
References
 1.Abadi, M., Cardelli, L., Curien, P.L.: Formal parametric polymorphism. Theor. Comput. Sci. 121(1&2), 9–58 (1993)MathSciNetCrossRefGoogle Scholar
 2.Abramsky, S., Jagadeesan, R.: A game semantics for generic polymorphism. Ann. Pure Appl. Logic 133(1), 3–37 (2005). Festschrift on the occasion of Helmut Schwichtenberg’s 60th birthdayMathSciNetCrossRefGoogle Scholar
 3.Abramsky, S., Jagadeesan, R., Malacaria, P.: Full abstraction for PCF. Inf. Comput. 163(2), 409–470 (2000)MathSciNetCrossRefGoogle Scholar
 4.Bainbridge, E.S., Freyd, P.J., Scedrov, A., Scott, P.J.: Functorial polymorphism. Theor. Comput. Sci. 70(1), 35–64 (1990)MathSciNetCrossRefGoogle Scholar
 5.de Lataillade, J.: Quantification du second ordre en sémentique des jeux: application aux isomorphismes de types. Ph.D. thesis, Paris 7 (2007)Google Scholar
 6.de Lataillade, J.: Secondorder type isomorphisms through game semantics. Ann. Pure Appl. Logic 151(2–3), 115–150 (2008)MathSciNetCrossRefGoogle Scholar
 7.Gabbay, M., Pitts, A.M.: A new approach to abstract syntax with variable binding. Formal Asp. Comput. 13(3–5), 341–363 (2002)CrossRefGoogle Scholar
 8.Girard, J.Y., Lafont, Y., Taylor, P.: Proofs and Types, vol. 7. Cambridge University Press, Cambridge (1989)MATHGoogle Scholar
 9.Hughes, D.: Hypergame semantics: full completeness for System F. Ph.D. thesis, D. Phil. thesis, Oxford University (2000)Google Scholar
 10.Hughes, D.J.D.: Games and definability for System F. In: Proceedings of the 12th Annual IEEE Symposium on Logic in Computer Science, LICS 1997, Washington, DC, USA, 76 pages. IEEE Computer Society (1997)Google Scholar
 11.Hyland, J.M.E., Ong, C.L.: On full abstraction for PCF: I, II, and III. Inf. Comput. 163(2), 285–408 (2000)MathSciNetCrossRefGoogle Scholar
 12.Jaber, G.: Operational nominal game semantics. In: Pitts, A. (ed.) FoSSaCS 2015. LNCS, vol. 9034, pp. 264–278. Springer, Heidelberg (2015). https://doi.org/10.1007/9783662466780_17CrossRefGoogle Scholar
 13.Jaber, G., Tzevelekos, N.: Trace semantics for polymorphic references. In: Proceedings of the 31st Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2016, New York, NY, USA, 5–8 July 2016, pp. 585–594 (2016)Google Scholar
 14.Laird, J.: A fully abstract trace semantics for general references. In: Arge, L., Cachin, C., Jurdziński, T., Tarlecki, A. (eds.) ICALP 2007. LNCS, vol. 4596, pp. 667–679. Springer, Heidelberg (2007). https://doi.org/10.1007/9783540734208_58CrossRefGoogle Scholar
 15.Laird, J.: Game semantics for a polymorphic programming language. J. ACM 60(4), 29:1–29:27 (2013)MathSciNetCrossRefGoogle Scholar
 16.Lassen, S.B., Levy, P.B.: Typed normal form bisimulation for parametric polymorphism. In: Proceedings of the 2008 23rd Annual IEEE Symposium on Logic in Computer Science, LICS 2008, Washington, DC, USA, pp. 341–352. IEEE Computer Society (2008)Google Scholar
 17.Longo, G., Milsted, K., Soloviev, S.: The genericity theorem and parametricity in the polymorphic lambdacalculus. Theor. Comput. Sci. 121(1–2), 323–349 (1993)CrossRefGoogle Scholar
 18.Mitchell, J.C.: On the equivalence of data representations. In: Lifschitz, V. (ed.) Artificial Intelligence and Mathematical Theory of Computation, pp. 305–329. Academic Press Professional Inc., San Diego (1991)CrossRefGoogle Scholar
 19.Pitts, A.M.: Nominal Sets: Names and Symmetry in Computer Science. Cambridge University Press, New York (2013)CrossRefGoogle Scholar
 20.Plotkin, G., Abadi, M.: A logic for parametric polymorphism. In: Bezem, M., Groote, J.F. (eds.) TLCA 1993. LNCS, vol. 664, pp. 361–375. Springer, Heidelberg (1993). https://doi.org/10.1007/BFb0037118CrossRefGoogle Scholar
 21.Reynolds, J.C.: Types, abstraction and parametric polymorphism. In: IFIP Congress, pp. 513–523 (1983)Google Scholar
 22.Strachey, C.: Fundamental concepts in programming languages. HigherOrder Symbolic Comput. 13(1), 11–49 (2000)CrossRefGoogle Scholar
 23.Wadler, P.: Theorems for free! In: Proceedings of the Fourth International Conference on Functional Programming Languages and Computer Architecture, FPCA 1989, pp. 347–359. ACM, New York (1989)Google Scholar
Copyright information
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made. The images or other third party material in this book are included in the book's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the book's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.