问题
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