小编Mic*_*ael的帖子

为什么不打印强制整个惰性 IO 值?

我正在使用http-client教程使用 TLS 连接获取响应正文。既然我可以观察到它print是由 调用的withResponse,为什么不print强制对以下片段中的输出进行完整响应?

withResponse request manager $ \response -> do
    putStrLn $ "The status code was: " ++
    body <- (responseBody response)
    print body
Run Code Online (Sandbox Code Playgroud)

我需要写这个:

response <- httpLbs request manager

putStrLn $ "The status code was: " ++
           show (statusCode $ responseStatus response)
print $ responseBody response
Run Code Online (Sandbox Code Playgroud)

我要打印的正文是一个懒惰的 ByteString。我仍然不确定是否应该print打印整个值。

instance Show ByteString where
    showsPrec p ps r = showsPrec p (unpackChars ps) r
Run Code Online (Sandbox Code Playgroud)

haskell conduit lazy-io haskell-pipes http-conduit

2
推荐指数
1
解决办法
212
查看次数

标签 统计

conduit ×1

haskell ×1

haskell-pipes ×1

http-conduit ×1

lazy-io ×1