0

I have the following code with a pipe which is ok without the second pipe (>-> P.mapM ( fillMD5)). fillMD5 is an operation a -> IO a.

runSafeT $ runEffect $
     every (senseRecursive5  startfpo)
        >-> P.mapM ( fillMD5)
        >-> P.map fp2rdf  
        >-> toNTriple houtfile   

The error is :

Couldn't match type `IO' with `Pipes.Safe.SafeT IO'
Expected type: Pipes.Safe.SafeT IO ()
  Actual type: IO ()
In the second argument of `($)', namely
  `runEffect

I understand that the type of mapM is

mapM :: Monad m => (a -> m b) -> Pipe a b m r

but I do not see how to lift this into Safe.SafeT?

Davorak
  • 7,362
  • 1
  • 38
  • 48
user855443
  • 2,596
  • 3
  • 25
  • 37

1 Answers1

6

SafeT is a monad transformer, and so SafeT IO is a composite monad with IO wrapped in SafeT. To use fillMD5, you need to lift the computation it produces to the composite monad using lift (from the MonadTrans class):

    >-> P.mapM (lift . fillMD5)

As fillMD5 produces an IO action, you can also use liftIO, which comes from the MonadIO instance of SafeT:

    >-> P.mapM (liftIO . fillMD5)
duplode
  • 33,731
  • 7
  • 79
  • 150
  • thank you very much. i was thinking of lift or liftIO but forgot the composition (ie. (lift fillMD5) ) and did not see my error! – user855443 May 26 '14 at 21:07