X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=code%2Funtyped_evaluator_complete.ml;h=f918d3a4c64a83d1ee0ac81b1344f9acf4aeaed3;hp=930491f1defa8c9871361fdc7964b97daa1f66c7;hb=44f72e6eda8faaa6d9d352c57fab8cff10676618;hpb=d2cd63fe26f3777ee6fb7a6005bf28e30c0381f0 diff --git a/code/untyped_evaluator_complete.ml b/code/untyped_evaluator_complete.ml index 930491f1..f918d3a4 100644 --- a/code/untyped_evaluator_complete.ml +++ b/code/untyped_evaluator_complete.ml @@ -1,5 +1,5 @@ (* - This is a simplified version of the code at ... + This is a simplified version of the code at http://lambda.jimpryor.net/code/untyped_full-1.7.tgz You can use this code as follows: 1. First, use a text editor to fill in the (* COMPLETE THIS *) portions. @@ -15,7 +15,7 @@ `reduce (App(Lambda("x",Var "x"),Lambda("y",Var "y")))` `evaluate (App(Lambda("x",Var "x"),Lambda("y",Var "y")))` - The two interpreters presented below are (VersionA) a substitute-and-replace + The two interpreters presented below are (VersionA) a substitute-and-repeat interpreter, and (VersionB) an environment-based interpreter. We discuss the differences between these in the course notes. @@ -61,7 +61,7 @@ and env = (identifier * term) list (* Operations for environments *) let empty = [] let shift (ident : identifier) binding env = (ident,binding) :: env -let rec lookup (sought_ident : ident) (env : env) : term option = +let rec lookup (sought_ident : identifier) (env : env) : term option = match env with | [] -> None | (ident, binding) :: _ when ident = sought_ident -> Some binding @@ -72,7 +72,7 @@ let rec lookup (sought_ident : ident) (env : env) : term option = eval raises this exception when it fails to reduce/evaluate a term, because it has components for which no reduction/evaluation is defined, such as `x y`. The - reduction-based interpreter just signals this with a normal + substitute-and-repeat interpreter just signals this with a normal return value; but the environment-based interpreter uses an exception to abort prematurely.