(Figure 1)
A part of the simply typed lambda calculus (Figure 1), it is implemented in Haskell as given below.
evaluate expression = do
case expression of
(Application (Lambda x ltype term) value) | isValue value = True -> substitute term x value
(Application value e2) | isValue value = True -> let e22 = evaluate e2 in Application value e22
(Application e1 e2) -> let e11 = evaluate e1 in Application e11 e2
However, this doesn't work for these test cases,
1) print (evaluate (Application (Var "x") (Var "y")))
2) print (evaluate (Application (Constant 3) (Var "y"))
"(Constant 3) is a value"
But, for the first test case, I know it's because (Var "x")
as e1
is terminal so it cannot transition. Does it mean I should add a Stuck
case? But I want to return an output suggesting the success of the transitions, if that's possible.
Thank you in advance...