Pipes.Safe - 如何使用mapM

use*_*443 0 haskell lifting haskell-pipes

我有以下代码与管道没有第二个管道(>-> P.mapM ( fillMD5)).fillMD5是一项行动a -> IO a.

runSafeT $ runEffect $
     every (senseRecursive5  startfpo)
        >-> P.mapM ( fillMD5)
        >-> P.map fp2rdf  
        >-> toNTriple houtfile   
Run Code Online (Sandbox Code Playgroud)

错误是:

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
Run Code Online (Sandbox Code Playgroud)

我明白的类型mapM

mapM :: Monad m => (a -> m b) -> Pipe a b m r
Run Code Online (Sandbox Code Playgroud)

但我不明白如何将其提升到Safe.SafeT

dup*_*ode 6

SafeT是一个monad变换器,SafeT IO也是一个IO包裹的复合monad SafeT.要使用fillMD5,您需要使用(从类中)将它生成的计算提升到复合monad :liftMonadTrans

    >-> P.mapM (lift . fillMD5)
Run Code Online (Sandbox Code Playgroud)

fillMD5生成IO动作时,您也可以使用liftIO来自以下MonadIO实例的动作SafeT:

    >-> P.mapM (liftIO . fillMD5)
Run Code Online (Sandbox Code Playgroud)