I’m having some trouble trying to incorporate a read and write statement into evaluateStatementInner function.
I’ve tried changing the return types of both functions without success.
I’m trying to convert a type IO(Env) into Env. I know that this can be done with binding in a function that returns an IO action but can I do it in the evaluateInner statement?
Cheers
Evaluating
ReadandWriteby necessity involves performing i/o. So bite the bullet and change the type ofevaluateStatementInnertoStmt -> Env -> IO Env(or, better, incorporate it directly intoevaluateStatement).You will then need to modify
evaluateListOfStatementsto be of type[Stmt] -> Env -> IO Env.So this now gives you a compile error
because
evaluateStatementInner innerStmt envyields anIO Env, butevaluateStatementInner (While boolExp innerStmt)wants anEnv.This is a case for monadic bind (and note the else branch needs updating to have the correct type as well):
You might not be comfortable with the monadic operators, so I’ll translate it into do-notation: