In another question, Bob presented the following interpreter for the untyped lambda calculus.
data Expr = Var String | Lam String Expr | App Expr Expr
data Value a = V a | F (Value a -> Value a)
interpret :: [(String, Value a)] -> Expr -> Value a
interpret env (Var x) = case lookup x env of
Nothing -> error "undefined variable"
Just v -> v
interpret env (Lam x e) = F (\v -> interpret ((x, v):env) e)
interpret env (App e1 e2) = case interpret env e1 of
V _ -> error "not a function"
F f -> f (interpret env e2)
Ivan Zakharyaschev remarked that this interpreter is call-by-value due to F f -> f (interpret env e2)
. How would the implementation of a call-by-name interpreter be different from the one presented above?
Plotkin studied call-by-name and call-by-value strategies for evaluating the lambda calculus in the 1970s.