developing exx
authorChris <chris.barker@nyu.edu>
Sat, 14 Mar 2015 13:18:30 +0000 (09:18 -0400)
committerChris <chris.barker@nyu.edu>
Sat, 14 Mar 2015 13:18:30 +0000 (09:18 -0400)
code/reduction.ml
exercises/_assignment6.mdwn

index 3882c7f..188a90b 100644 (file)
@@ -10,8 +10,8 @@ let rec free_in (ident:identifier) (term:lambdaTerm) : bool =
   match term with
     | Constant _ -> false
     | Var(var_ident) -> var_ident = ident
-    | Abstract(bound_ident, body) -> bound_ident <> ident && free_in ident body
-    | App(head, arg) -> free_in ident head || free_in ident arg
+(*    | Abstract(bound_ident, body) ->  COMPLETE THIS LINE *)
+(*    | App(head, arg) -> COMPLETE THIS LINE *)
     | IfThenElse(test, yes, no) -> free_in ident test || free_in ident yes || free_in ident no
     | Let(bound_ident, arg, body) -> free_in ident arg || (bound_ident <> ident && free_in ident body)
 
index aabcbe0..f6a4803 100644 (file)
@@ -24,5 +24,33 @@ recursive reduction function.)
 
 <!-- just add early no-op cases for Ka and Sab -->
 
-## Evaluation in the untyped lambda calculus
+## Evaluation in the untyped lambda calculus: substitution
+
+Once you grok reduction and evaluation order in Combinatory Logic,
+we're going to begin to construct an evaluator for a simple language
+that includes lambda abstraction.  We're going to work through the
+issues twice: once with a function that does substitution in the
+obvious way.  You'll see it's somewhat complicated.  The complications
+come from the need to worry about variable capture.  (Seeing these
+complications should give you an inkling of why we presented the
+evaluation order discussion using Combinatory Logic, since we don't
+need to worry about variables in CL.)  
+
+We're not going to ask you to write the entire program yourself.
+Instead, we're going to give you [[the complete program, minus a few
+little bits of glue|code/reduction.ml]].  What you need to do is
+understand how it all fits together.  When you do, you'll understand
+how to add the last little bits to make functioning program.  Here's a
+first target for when you get it working:
+
+    # reduce (App (Abstract ("x", Var "x"), Constant (Num 3)));;
+    - : lambdaTerm = Constant (Num 3)
+
+1. In the previous homework, you built a function that took an
+identifier and a lambda term and returned a boolean representing
+whether that identifier occured free inside of the term.  Your first
+task is to adapt your previous solution as necessary to work with the
+code base.  Once you have your function working, you should be able to
+run queries such as this:
+