Lift Monad Reader local

本秂侑毒 提交于 2019-12-23 05:27:44

问题


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.

来源:https://stackoverflow.com/questions/37187933/lift-monad-reader-local

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!