我试图在我的 Scotty 应用程序中引入 Reader monad,作为在内部为 URL 扩展提供统一根路径的一种方式。我似乎无法理解 Scotty 如何处理 monad 转换 - 通常,我只会看到类似的东西runTransformerT ...
,但scottyT
有很多内部管道要做,所以结果实际上只是一个(如果在函数中使用,则MonadIO n => n ()
强制,就像我在这里)。IO ()
main
到目前为止,这是我的代码:
main :: IO ()
main = scottyT 3000
(\x -> runReaderT x "foo.com")
id $ do
root <- lift ask
get "/" $
text root
我得到的错误是:
src/Main.hs:16:21:
Couldn't match type ‘IO’ with ‘ReaderT r0 IO’
Expected type: ReaderT r0 IO a
Actual type: IO a
In the first argument of ‘runReaderT’, namely ‘x’
In the expression: runReaderT x "foo.com"
我该如何使用这个魔法?