-->

Lift Monad Reader local

2019-06-14 04:09发布

问题:

import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Error

data Context
data Memory 
data Functions

data InterpreterM a = ExeInterpreter a | PropInterpreter a

newtype InterpreterMT m a = InterpreterMT { runInterpreterMT :: m (InterpreterM a) }
type Interpreter = InterpreterMT (StateT (Memory, Functions) (ReaderT (Context, Context) (ErrorT String IO)))

data Stmt
data Stmts = EmptyStmts | Statements Stmt Stmts

interpretStmt :: Stmt -> Interpreter Context

interpreter :: Stmts -> Interpreter ()
interpreter EmptyStmts = return () 
interpreter (Statements s stmts) = do
    currEnv <- interpretStmt s
    local (\(prev, _) -> (prev, currEnv)) $ interpreter stmts

The problem is in last line- there is no lifting- I know it. But I don't know how to put lift here because my experiments also gives me errors. I am asking for help.