1

I'm using Pipes.Files, which in turn relies upon Pipes.Safe. I have a pipeline like this:

import Pipes
import Pipes.Files
import Pipes.Safe
import qualified Pipes.Prelude as P


allFiles :: (MonadIO m, MonadSafe m) => FilePath -> Producer FilePath m ()
allFiles path = find path (glob "*.hs" <> regular)

main :: IO ()
main = do
    args <- parseArgsOrExit patterns =<< getArgs  -- docopt stuff, not relevant
    let ins = args `getAllArgs` argument "paths"
    conf <- readConfig args
    forM_ ins $ \path -> do
        let source = allFiles path  -- here lies the problem
                  >-> P.mapM (liftIO . analyze conf)
                  >-> P.map (filterResults conf)
                  >-> P.filter filterNulls
        runSafeT $ runEffect $ exportStream conf source

The problem is that the type of analyze is

analyze :: Config -> FilePath -> IO Result

while allFiles has MonadSafe m and MonadIO m constraints. In theory liftIO should take care of this, but instead I get this error:

Main.hs:45:22:
    No instance for (Pipes.Safe.MonadSafe IO)
      arising from a use of ‘allFiles’
    In the first argument of ‘(>->)’, namely ‘allFiles path’
    In the first argument of ‘(>->)’, namely
      ‘allFiles path >-> P.mapM (liftIO . analyze conf)’
    In the first argument of ‘(>->)’, namely
      ‘allFiles path >-> P.mapM (liftIO . analyze conf)
       >-> P.map (filterResults conf)’

Main.hs:49:20:
    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 $ exportStream conf source’
    In a stmt of a 'do' block:
      runSafeT $ runEffect $ exportStream conf source
    In the expression:
      do { let source
                 = allFiles path >-> P.mapM (liftIO . analyze conf)
                   >-> P.map (filterResults conf)
                   >-> P.filter filterNulls;
           runSafeT $ runEffect $ exportStream conf source }

There is also a second error that I don't now how to interpret.

EDIT: Here are the other type signatures:

filterResults :: Config -> Result -> Result
filterNulls :: Result -> Bool
exportStream :: Config -> Producer Result IO () -> Effect IO ()
rubik
  • 8,814
  • 9
  • 58
  • 88

0 Answers0