Как заставить ReaderT работать с другим монадным преобразователем?
Я хотел бы встроитьReaderT
в другой монадный трансформатор. Как мне это сделать? Пример ниже используетScotty
но я думаю, что было бы то же самое с любой другой монадой.
{-# LANGUAGE OverloadedStrings #-}
import qualified Web.Scotty
import Web.Scotty.Trans
import Data.Text.Lazy
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Reader
import Control.Monad.Trans
data Config = Config Text
main :: IO ()
main = do
let config = Config "Hello World"
-- how to I make this line work?
scottyT 3000 id id routes
routes :: ScottyT Text (ReaderT Config IO) ()
routes = do
get "/" info
info :: ActionT Text (ReaderT Config IO) ()
info = do
-- this part seems like it works!
Config message <- lift ask
text $ "Info: " `append` message
Это ошибки на линииscottyT 3000 id id routes
, так какscottyT
ожидаетScottyT Text IO ()
, Как мне сделать эту работу? Вот текущие ошибки:
Server.hs: line 24, column 24:
Couldn't match type `ReaderT Config IO' with `IO'
Expected type: ScottyT Text IO ()
Actual type: ScottyT Text (ReaderT Config IO) ()