【发布时间】:2017-02-23 20:51:19
【问题描述】:
我刚刚遇到了withSession :: (Session -> IO a) -> IO a 的wreq 包。我想逐行评估延续,但我找不到任何方法。
import Network.Wreq.Session as S
withSession $ \sess -> do
res <- S.getWith opts sess "http://stackoverflow.com/questions"
-- print res
-- .. other things
在上面的 sn-p 中,我如何在 ghci 中评估 print res?换句话说,我可以在ghci中输入Session吗?
【问题讨论】:
-
withSession函数正是提供会话的函数。您可以通过在传递给withSession的函数体内操作sess参数来“获取”会话。换句话说,如果您有main = withSession ..,那么只需在 ghci 提示符下键入main(或:main)即可运行该操作。至于“逐行评估延续”,您必须自己实现该逻辑。 -
哇,好问题!能够为 CPS 风格的库函数重新输入 GHCi repl 确实很棒。
标签: haskell