Scotty和Reader Monad

时间:2014-12-05 14:22:02

标签: haskell monads monad-transformers scotty reader-monad

我试图在我的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"

我如何使用这种魔力?

0 个答案:

没有答案