From 2e46c8cacfb881ce410c5d85d164b5c110360607 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Tue, 20 Feb 2018 05:23:05 -0600 Subject: [PATCH] look up names again --- lambda.ml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lambda.ml b/lambda.ml index bf6712c..3655348 100644 --- a/lambda.ml +++ b/lambda.ml @@ -19,6 +19,11 @@ let rec string_of_term (t: Types.term) = "(" ^ (string_of_term t1) ^ " " ^ (string_of_term t2) ^ ")" | TmVar(x) -> x +let rec string_of_term_in_ctx ctx tm = + match ctx with + | [] -> (string_of_term tm) + | (n, t)::r -> if t = tm then n else (string_of_term_in_ctx r tm) + let rec string_of_ctx (c: Types.context) = match c with | [] -> "" @@ -89,7 +94,7 @@ let _ = match x with | Types.Term t -> let (ctx', r) = eval (ctx, t) in - print_endline (string_of_term r); flush stdout; + print_endline (string_of_term_in_ctx ctx r); flush stdout; loop ctx' | Types.Assign (n, t) -> let (ctx', r) = eval (ctx, t) in