使用:
mailHandler = do
name <- param "name"
email <- param "email"
renderSendMail $ forwardMail name email
main = scotty 3000 $ post "/mail" mailHandler
我收到以下类型错误:
Couldn't match type `IO'
with `Web.Scotty.Internal.Types.ActionT T.Text IO'
Expected type: Web.Scotty.Internal.Types.ActionT T.Text IO ()
Actual type: IO ()
In a stmt of a 'do' block: renderSendMail $ forwardMail name email
In the expression:
do { name <- param "name";
email <- param "email";
renderSendMail $ forwardMail name email }
In an equation for `mailHandler':
mailHandler
= do { name <- param "name";
email <- param "email";
renderSendMail $ forwardMail name email }
Failed to install server-0.0.1
cabal: Error: some packages failed to install:
server-0.0.1 failed during the building phase. The exception was:
ExitFailure 1
花了几个小时后,我仍然没有看到如何解决这个问题。如果我使用Scotty内部的函数,没问题,但如果我想在外部处理任何东西,我会得到上面的错误。如何通过此Web.Scotty.Internal.Types.ActionT T.Text IO ()
答案 0 :(得分:10)
Web.Scotty.Internal.Types.ActionT T.Text IO ()
是 monad转换器超过IO
。这些通常会实现MonadIO
类,以便您可以使用liftIO
函数(来自Control.Monad.IO.Class
,如果尚未导入)来“提升”IO
行为进入他们:
liftIO . renderSendMail $ forwardMail name email