Question

I’m trying to understand code from http://www.yesodweb.com/book/conduits. After some fixes (like replacing Resource with MonadResource) it still won’t compile:

sumSink :: MonadResource m => Sink Int m Int
sumSink = CL.fold (+) 0

sum' :: [Int] -> Int
sum' input = runST $ runResourceT $ CL.sourceList input $$ sumSink

gives me the following error:

    Couldn't match type `GHC.ST.ST s' with `IO'
    When using functional dependencies to combine
      Control.Monad.Trans.Control.MonadBaseControl
        (GHC.ST.ST s) (GHC.ST.ST s),
        arising from the dependency `m -> b'
        in the instance declaration in `Control.Monad.Trans.Control'
      Control.Monad.Trans.Control.MonadBaseControl IO (GHC.ST.ST s),
        arising from a use of `runResourceT'
        at D:\Works\stablename\test.hs:43:22-33
    In the expression: runResourceT
    In the second argument of `($)', namely
      `runResourceT $ CL.sourceList input $$ sumSink'

I’m using GHC 7.4.1 and conduit-0.4.2.

P.S. Is there any tutorial which isn’t broken / was written with conduit-0.4 in mind?

Was it helpful?

Solution

Answering my own question:

  • Monad m should be used instead of Resource m.
  • runResourceT needs to be applied if a function like sinkFile was used somewhere in the chain, because sinkFile requires MonadResource m and there is no instance for MonadResource IO.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top