1

如果问题很愚蠢,我对 Haskell 很陌生,所以提前抱歉,但我无法在谷歌中找到解决方案。

假设我有这个使用Scotty Web 框架的程序:

responseUserByName :: ActionM ()
responseUserByName = do name <- param "name"
                        user <- liftAndCatchIO $ getUserByUserName name
                        json user

我想添加一个日志,因为它在运行时失败,我不知道为什么。所以我的想法是在 do 块中添加一些打印来检查值。

但由于该do块必须返回 aActionM我无法打印并返回一个IO. 好吧,或者至少我不知道怎么做。

问候

4

1 回答 1

2

我猜那ActionM是来自Scotty的。在这种情况下,您可以简单地使用 提升 IO 操作liftIO,就像您已经使用liftAndCatchIO

responseUserByName :: ActionM ()
responseUserByName =
    do name <- param "name"
       user <- liftAndCatchIO $ getUserByUserName name
       liftIO $ putStrLn "this is a log message"
       json user
于 2018-08-15T19:56:48.403 回答