From: Jim Date: Sun, 22 Mar 2015 15:08:59 +0000 (-0400) Subject: change env implementations to assoc list X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=86a3a58658e1b6466ec3cef5265f7de9df321713 change env implementations to assoc list --- 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' (*