From e74b6fae50222f3f5438180efe3dc01fb545e1f6 Mon Sep 17 00:00:00 2001
From: Chris
Date: Tue, 10 Mar 2015 10:55:12 -0400
Subject: [PATCH] edits
---
topics/week5_system_F.mdwn | 45 +++++++++++++++++++++++----------------------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/topics/week5_system_F.mdwn b/topics/week5_system_F.mdwn
index f89748b7..fabb868b 100644
--- a/topics/week5_system_F.mdwn
+++ b/topics/week5_system_F.mdwn
@@ -126,7 +126,7 @@ Exercise: convince yourself that `zero` has type `N`.
[By the way, in order to keep things as simple as possible here, the
types used in this definition of the ancillary functions given here
are not as general as they could be; see the discussion below of type
-inference and principle types in the OCaml type system.]
+inference and principal types in the OCaml type system.]
The key to the extra expressive power provided by System F is evident
in the typing imposed by the definition of `pred`. The variable `n`
@@ -504,7 +504,7 @@ Question: why do thunks work? We know that `blackhole ()` doesn't terminate, so
terminate?
-Type inference and principle types
+Type inference and principal types
----------------------------------
As we mentioned, the types given to some of the functions defined
@@ -514,49 +514,50 @@ might be.
let pair = Î»x:N. Î»y:N. Î»z:N->N->N. z x y in
...
-For instance, in the definition of `pair`, we assumed that the
-function `z` would return something of type `N`, i.e., a Church
-number. But we can give a more general treatment.
+For instance, in the definition of `pair`, repeated here, we assumed
+that the function `z` would return something of type `N`, i.e., a
+Church number. But we can give a more general treatment.
let general_pair = ÎÎ±. ÎÎ². Î»x:Î±. Î»y:Î². ÎÏ. Î»z:Î±->Î²->Ï. z x y in
...
In this more general version, the pair function accepts any kind of
objects as its first and second element. The resulting pair will
-expect any function that is ready to handle arguments of the same
-types the pair was built from, and there is no restriction on the type
-(Ï) of the result returned from the pair-manipulation function.
+expect a handler function (`z`) that is ready to handle arguments of
+the same types the pair was built from, but there is no restriction on
+the type (Ï) of the result returned by the handler function.
-The type we gave the `pair` function above is a specific instance of
-the more general type, with `Î±`, `Î²`, and `Ï` all set to `N`.
-Many practical type systems guarantee that under reasonably general
-conditions, there will be a ***principle type***: a type such that
-every other possible type for that expression is a more specific
-version of the principle type.
+The number specific type we gave the `pair` function above (i.e.,
+`N->N->(N->N->N)->N`) is a specific instance of the more general type,
+with `Î±`, `Î²`, and `Ï` all set to `N`. Many practical type systems
+guarantee that under reasonably general conditions, there will be a
+***principal type***: a type such that every other possible type for
+that expression is a more specific version of the principal type.
As we have seen, it is often possible to infer a type for an
expression based on its internal structure, as well as by the way in
which it is used. In the simply-typed lambda calculus, types for a
well-typed expression can always be inferred; this is what enables
programs to be written "Curry-style", i.e., without explicit types.
-Unfortunately, for unrestricted System F, type inference is
-undecidable, so a certain amount of explicit type specification is
-required.
-OCaml places restrictions on its type system that makes type inference
-feasible. When programming interpreters and compilers infer types,
-they often (but not always) aim for the principle type (if one is
+Unfortunately, reliably inferring types is not always possible. For
+unrestricted System F, type inference is undecidable, so a certain
+amount of explicit type specification is required. OCaml places
+restrictions on its type system that makes type inference feasible.
+
+When programming language interpreters and compilers infer types, they
+often (but not always) aim for the principal type (if one is
guaranteed to exist).
# let pair a b z = z a b;;
val pair : 'a -> 'b -> ('a -> 'b -> 'c) -> 'c =
For instance, when we define the same `pair` function given above in
-the OCaml interpreter, it correctly infers the principle type we gave
+the OCaml interpreter, it correctly infers the principal type we gave
above (remember that OCaml doesn't bother giving the explicit
universal type quantifiers required by System F).
-Computing principle types involves unification algorithms. Inferring
+Computing principal types involves unification algorithms. Inferring
types is a subtle and complicated business, and all sorts of
extensions to a programming language can interfere with it.
--
2.11.0