Consider the combinators $\mathbf{S} \equiv \lambda xyz . xz(yz),ドル $\mathbf{I} = \lambda w.w$ and their application $\mathbf{SI}$. Is this term typable à la Curry?
From what I did so far, it seems it is not: I tried to construct a deduction tree from bottom to top, and on the top I concluded that in order to type $\mathbf{SI}$ the variable $x$ would have to have two different types. Is this correct? Is there an elegant way to show this?
-
$\begingroup$ Possibly useful: Lambda calculus typing $\endgroup$MJD– MJD2015年07月07日 12:36:10 +00:00Commented Jul 7, 2015 at 12:36
-
$\begingroup$ $ SIxy = y(xy) \ ,\ SI : (y \rightarrow t) \rightarrow (y = t\rightarrow u) \rightarrow u \sim ((t\rightarrow u)\rightarrow t) \rightarrow (t\rightarrow u) \rightarrow u $ $\endgroup$Will Ness– Will Ness2025年10月12日 17:58:30 +00:00Commented Oct 12 at 17:58
1 Answer 1
Indeed $\mathbf{S}$ is typeable:
- $ x : \alpha \rightarrow \beta \rightarrow \gamma $.
- $ y : \alpha \rightarrow \beta $.
- $ z : \alpha $.
- $ (x\ z) : \beta \rightarrow \gamma\ $ (from 1,3).
- $ (y\ z) : \beta\ $ (from 2,3).
- $ (x\ z)(y\ z) : \gamma\ $ (from 4,5).
- $ \lambda x. \lambda y . \lambda z . (x\ z)(y\ z) \ : \ (\alpha \rightarrow \beta \rightarrow \gamma) \rightarrow (\alpha \rightarrow \beta) \rightarrow \alpha \rightarrow \gamma \ $ (from 1,2,3,6).
If you start from variable occurrences and propagate the information you infer from their usage (it is applied to something, then it must be an arrow of something; or it is the argument of something, then it must have the same type of the leftmost type of the something's arrow type), then you either find conflicting constraints, or conclude the process, thus having a counterexample or a type. Roughly, it is the idea behind Hindley–Milner W algorithm for type inference.
Let us see how to do it by considering $(\mathbf{S I})$ and generalising our previous argument.
- Let $ \lambda w. w : \delta \rightarrow \delta $.
- Then we need to unify our previous type of $x$ in 1 with those of 8, i.e. $\alpha \rightarrow (\beta \rightarrow \gamma)$ with $\delta \rightarrow \delta$. This means that $ \alpha = \delta $ and $\beta\rightarrow\gamma\ =\ \delta $.
- Hence we found the right type unifier; let us substitute $ \beta \rightarrow \gamma $ for $ \alpha $ in 7, and also for $ \delta $ in 8. We obtain $$ \mathbf{S} \ : \ ((\beta \rightarrow \gamma) \rightarrow \beta \rightarrow \gamma) \rightarrow ((\beta \rightarrow \gamma) \rightarrow \beta) \rightarrow (\beta \rightarrow \gamma) \rightarrow \gamma $$ and $$ \mathbf{I} \ :\ (\beta \rightarrow \gamma) \rightarrow \beta \rightarrow \gamma \text{.} $$ We conclude: $$ (\mathbf{SI}) \ :\ ((\beta \rightarrow \gamma) \rightarrow \beta) \rightarrow (\beta \rightarrow \gamma) \rightarrow \gamma \text. $$
-
$\begingroup$ Indeed $\mathbf{S}$ is typable, as you've showned; however, it could still happen that $\mathbf{SI}$ was not typed! (example: $x$ is typable, $xx$ is not). But I do think $\mathbf{SI}$ is typable, with an argument similar to yours. $\endgroup$essay– essay2015年07月03日 19:52:12 +00:00Commented Jul 3, 2015 at 19:52
-
$\begingroup$ Yes, you are right---in general it is not true that if both $M,N$ are typeable, then necessarily $(M N)$ is so. $\endgroup$Marco Solieri– Marco Solieri2015年07月04日 08:51:39 +00:00Commented Jul 4, 2015 at 8:51
-
$\begingroup$ I extended my previous answer to consider the whole term and to illustrate how to infer types. $\endgroup$Marco Solieri– Marco Solieri2015年07月04日 09:34:36 +00:00Commented Jul 4, 2015 at 9:34