我一直在使用 Control.Proxy.TCP 库,并想从网络源创建一个生产者。
producer :: Proxy p => HostName -> ServiceName -> () -> Producer p BS.ByteString IO ()
producer h p () = runIdentityP $
lift $ connect h p $ \(s, r) ->
runProxy $ nsocketReadS s >-> pxy >-> socketWriteD s
where
pxy () = runIdentityP $ do
respond "resource-id" -- ask for "resource-id"
bs <- request 1024 -- fetch up to 1024 bytes
lift $ respond bs -- and produce them from the outer proxy
return ()
上面的代码没有类型检查:
Couldn't match type `p0 a'0 a1 a0 BS.ByteString m0' with `IO'
Expected type: ()
-> ProxyFast Int BS.ByteString () BS.ByteString IO ()
Actual type: ()
-> ProxyFast
Int
BS.ByteString
()
BS.ByteString
(p0 a'0 a1 a0 BS.ByteString m0)
()
In the second argument of `(>->)', namely `pxy'
In the first argument of `(>->)', namely `nsocketReadS s >-> pxy'
In the second argument of `($)', namely
`nsocketReadS s >-> pxy >-> socketWriteD s'
我看到 nsocketReadS 和 socketWriteD 的基本单子是 IO ,而我需要不同的类型。我该如何纠正这个问题?