我正在试验导管包。还找到了 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 中。但我就是不知道该怎么做。
...?