From 86a3a58658e1b6466ec3cef5265f7de9df321713 Mon Sep 17 00:00:00 2001 From: Jim Date: Sun, 22 Mar 2015 11:08:59 -0400 Subject: [PATCH] change env implementations to assoc list --- code/untyped_evaluator.ml | 16 ++++++++-------- code/untyped_evaluator_complete.ml | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/code/untyped_evaluator.ml b/code/untyped_evaluator.ml index 3fe3ac62..92efa6ea 100644 --- a/code/untyped_evaluator.ml +++ b/code/untyped_evaluator.ml @@ -56,16 +56,16 @@ and result = term (* This simplified code just provides a single implementation of environments; but the fuller code provides more. *) -and env = identifier -> term option +and env = (identifier * term) list (* Operations for environments *) -let empty = fun _ -> None -let shift (ident : identifier) binding env = - fun (sought_ident : identifier) -> - if ident = sought_ident - then Some binding - else env sought_ident -let lookup sought_ident env = env sought_ident +let empty = [] +let shift (ident : identifier) binding env = (ident,binding) :: env +let rec lookup (sought_ident : ident) (env : env) : term option = + match env with + | [] -> None + | (ident, binding) :: _ when ident = sought_ident -> Some binding + | _ :: env' -> lookup sought_ident env' (* diff --git a/code/untyped_evaluator_complete.ml b/code/untyped_evaluator_complete.ml index ed34138d..d9b158c6 100644 --- a/code/untyped_evaluator_complete.ml +++ b/code/untyped_evaluator_complete.ml @@ -56,16 +56,16 @@ and result = term (* This simplified code just provides a single implementation of environments; but the fuller code provides more. *) -and env = identifier -> term option +and env = (identifier * term) list (* Operations for environments *) -let empty = fun _ -> None -let shift (ident : identifier) binding env = - fun (sought_ident : identifier) -> - if ident = sought_ident - then Some binding - else env sought_ident -let lookup sought_ident env = env sought_ident +let empty = [] +let shift (ident : identifier) binding env = (ident,binding) :: env +let rec lookup (sought_ident : ident) (env : env) : term option = + match env with + | [] -> None + | (ident, binding) :: _ when ident = sought_ident -> Some binding + | _ :: env' -> lookup sought_ident env' (* -- 2.11.0