我使用的是Control.Monad.Except,並且我被困在一個地方,在那裏我必須強制執行ExceptT AppError m a
操作以獲取IO
操作,然後將其包裝回來如果你想知道爲什麼這是必需的,這是因爲我需要運行的底層庫函數只接受IO操作,在這種情況下,它將是Database.PostgreSQL.Simple.withTransaction :: Connection -> IO a -> IO a
如何將IO(ea)轉換爲ExceptT ema
如何編寫概念相當於以下內容:
type AppM = ExceptT AppError (ReaderT Env (LoggingT IO))
runAppM :: Env -> AppM a -> a
withTransaction :: AppM a -> AppM a
withTransaction appm = do
conn <- getDbConnection
env <- getEnv
liftIO $ PGS.withTransaction conn $ runAppM appm
這裏是我遇到了錯誤:
Excepted type: ExceptT AppError (ReadertT Env (LoggingT IO)) a
Actual type: ExceptT AppError (ReadertT Env (LoggingT IO)) (Either AppError a)
你的問題的標題和正文是完全不同的問題。 –