gpt4 book ai didi

haskell - 导管和网络导管 : Combine MonadResource and IO

转载 作者:行者123 更新时间:2023-12-04 19:11:47 24 4
gpt4 key购买 nike

我正在试验管道包。还找到了 network-conduit 包,我尝试制作一个简单的 TCP 客户端,它将文件的内容发送到套接字:

import Data.Conduit
import Data.Conduit.Binary
import Data.Conduit.Network
import Data.ByteString.Char8 (pack)

sendFile fileName appData = runResourceT $
sourceFile fileName $$ appSink appData

main = runTCPClient (clientSettings 8000 (pack "localhost")) (sendFile "book.tex")

但是,这不起作用,因为应用程序接收器不是 ResourceT:
[1 of 1] Compiling Main             ( Conduit2.hs, interpreted )

Conduit2.hs:9:63:
Occurs check: cannot construct the infinite type: m0 = ResourceT m0
Expected type: Application (ResourceT m0)
Actual type: AppData (ResourceT m0) -> m0 ()
In the return type of a call of `sendFile'
In the second argument of `runTCPClient', namely
`(sendFile "book.tex")'
Failed, modules loaded: none.

但是,如果没有 runResourceT,它显然也无法工作:
[1 of 1] Compiling Main             ( Conduit2.hs, interpreted )

Conduit2.hs:9:63:
No instance for (MonadResource IO)
arising from a use of `sendFile'
...etc...

我的猜测是我应该在不实际管理资源的情况下将 appSink(其中 m=IO)包装到 ResourceT 中。但我就是不知道该怎么做。

……?

最佳答案

我自己想出来了……只需要将整个 runTCPClient 包装到 runResourceT 中。

关于haskell - 导管和网络导管 : Combine MonadResource and IO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14292748/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com