type ErrorOrValue = Either InterpreterError Value
evaluateExpression :: [Value] -> IR.Expression -> ErrorOrValue
evaluateExpression as (IR.Application l r)
| Left _ <- arg = arg
| Right (Partial ac b as) <- f = foo as f arg
| Right _ <- f = Left NonFunctionApplication
| otherwise = f
where
f = evaluateExpression as l >>= forceValue
arg = evaluateExpression as r
I need to call foo with f and arg making sure that they are not Left.
Can I reduce the pattern matching and instead use binds and other monad operations?
You can use
do. Your code checksargbeforef, andfooappears to return anErrorOrValue, so it does not need to be lifted into theMonad. Also, theasthat is passed tofoois that extracted from thePartial, not the argument toevaluateExpression. Here is some completely untested code: