Is Milner let polymorphism a rank 2 feature?

后端 未结 5 1220
难免孤独
难免孤独 2021-01-31 04:25

let a = b in c can be thought as a syntactic sugar for (\\a -> c) b, but in a typed setting in general it\'s not the case. For example, in the Milne

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 04:51

    W.r.t. to the four questions asked:

    • A key insight in this matter is that rather than just typing a lambda-abstraction with a potentially polymorphic argument type, we are typing a (sugared) abstraction that is (1) applied exactly once and, moreover, that is (2) applied to a statically known argument. That is, we can first subject the "argument" (i.e. the definiens of the local definition) to type reconstruction to find its (polymorphic) type; then assign the found type to the "parameter" (the definiendum); and then, finally, type the body in the extended type context.

      Note that that is considerably more easy than general rank-2 type inference.

    • Note that, strictly speaking, let .. = .. in .. is only syntactic sugar in System F if you demand that the definiendum carries a type annotation: let .. : .. = .. in .. .

    • Here are two solutions for T in (\a :: T -> (a True, a 1)) in System F: forall b. (forall a. a -> b) -> (b, b) and forall c d. (forall a b. a -> b) -> (c, d). Note that neither one of them is more general than the other. In general, System F does not admit principal types.

    • I suppose this holds for the simply typed lambda-calculus?

提交回复
热议问题