I was given an exercise that asked me to assign a simple type to the lambda term: $$ \lambda a.a(\lambda yt.t)(ya) $$ but I couldn't find one, furthermore, the lambda term seems untypable to me because of the double reference to $a$.
This is my reasoning:
- let $t$ be of type $\alpha$, then $\lambda t.t$ has type $\alpha \rightarrow \alpha$;
- let then $y$ have type $\beta$, and so $\lambda yt.t$ has type $\beta \rightarrow \alpha \rightarrow \alpha$;
- let now give $a$ the type $\beta \rightarrow \alpha \rightarrow \alpha \rightarrow \alpha \rightarrow \alpha$, in order for the term $a(\lambda yt.t)$ to be of type $\alpha \rightarrow \alpha$.
From here I want $(ya)$ to be of type $\alpha$, so that the final term $a(\lambda yt.t)(ya)$ has a well-defined type, but the problem is that $y$ and $a$ both have already some defined types, which are not compatible (I cannot apply $a$ to $y$). However I assign types to $y$ and $a$, and I cannot find a type compatibility.
Can you please help me out? Is the lambda term typable in the first place? And if so, where am I wrong?