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