我正在试验导管包.我还找到了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")
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用,因为app sink不属于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.
Run Code Online (Sandbox Code Playgroud)
但是,如果没有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...
Run Code Online (Sandbox Code Playgroud)
我的猜测是我应该将appSink(其中m = IO)包装到ResourceT中而不实际管理资源.但我无法弄清楚如何做到这一点.
...?
| 归档时间: |
|
| 查看次数: |
333 次 |
| 最近记录: |