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问题在最后一行--没有提升--我知道。但我不知道如何将lift放在这里,因为我的实验也会给我带来错误。我在寻求帮助。
发布于 2020-08-21 19:41:42
如果希望将诸如local之类的函数提升为内部monad,则需要函数的map...T类。
例如,如果您有一个WriterT [String] (ReaderT Int (Either String)) a,并且想要在不同的读卡器环境中运行something:
mapWriterT (local (+1)) somethinghttps://stackoverflow.com/questions/37187933
复制相似问题