Add print in Scotty do block

心已入冬 提交于 2021-02-10 18:10:31

问题


I'm very new to Haskell so sorry in advance if the question is silly, but I was not able to find the solution in google.

Let's say that I have this program using the Scotty web framework:

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

I would like to add a log since it is failing at runtime and I cannot tell why. So my idea was to add some print in the do block to check values.

But since the do block has to return a ActionM I cannot print and return an IO. Well or at least I don't know how.

Regards


回答1:


I'm going to guess that ActionM is from Scotty. In that case, you can simply lift IO actions with liftIO, like you already do with liftAndCatchIO:

responseUserByName :: ActionM ()
responseUserByName =
    do name <- param "name"
       user <- liftAndCatchIO $ getUserByUserName name
       liftIO $ putStrLn "this is a log message"
       json user


来源:https://stackoverflow.com/questions/51865453/add-print-in-scotty-do-block

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!