As part of a mini interpreter that I'm writing in Haskell, I'm writing a function that does the following: In case of eval (App e1 e2), I want to recursively evaluate e1 (eval e1), setting the result to v1. Then using Switch/Case, I want to check the pattern of the v1 and if it's not an Error then recursively evaluate e2 (eval e2) and setting that value to v2. Using these two values v1 and v2, then I apply another function (appVals) on those values.
eval :: Exp -> Error Val
eval (App e1 e2) = appVals v1 v2 where
v1 = case (eval e1) of
Error err -> Error "Not an application"
/= Error err -> eval e1 = v1
v2 = case (eval e2) of
Error err -> Error "Not an application"
/= Error err -> eval e2 = v2
I think I may have figured it out but I'm not entirely sure I've done the switch/case part correctly. Any ideas/suggests?