gpt4 book ai didi

haskell - Scotty 帖子类型不允许效果

转载 作者:行者123 更新时间:2023-12-04 22:46:05 24 4
gpt4 key购买 nike

和:

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 ()

最佳答案

Web.Scotty.Internal.Types.ActionT T.Text IO ()IO 上的 monad 转换器。这些通常实现 MonadIO 类,以便您可以使用 liftIO 函数(来自 Control.Monad.IO.Class ,如果尚未导入)将 IO 操作“提升”到它们中:

liftIO . renderSendMail $ forwardMail name email

关于haskell - Scotty 帖子类型不允许效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25588883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com