Question

I am experimenting with the conduit package. Having also found the network-conduit package, I tried to make a simple TCP client which sends the contents of a file to a socket:

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")

This does not work, however, since the app sink doesn't live an a 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.

Without the runResourceT, however, it clearly can't work either:

[1 of 1] Compiling Main             ( Conduit2.hs, interpreted )

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

My guess is that I should wrap the appSink (where m=IO) into ResourceT without actually managing resources. But I just can't figure out how to do that.

...?

Was it helpful?

Solution

Figured it out myself... just needed to wrap the whole runTCPClient into runResourceT.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top