我一直在玩Control.Proxy.TCP庫,並希望從網絡源創建一個Producer。Haskell Control.Proxy.TCP Producer
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而我需要不同的類型。我該如何糾正這個問題?
你真的需要連接到代理插座嗎?也許你可以連接到管道以外的套接字,並將它傳遞給你的生產者使用socketReadS/socketWriteD? – bennofs
如果你願意,你可以看看這個:https://bitbucket.org/Dwilson1234/haskell-web-server。這可能有助於解決您的問題。 – Dwilson