[Haskell-beginners] yet another monad question

Ovidiu Deac ovidiudeac at gmail.com
Sat Feb 4 11:49:50 CET 2012

I have the following code which works fine:

type File = (String, String) --name and content

readDir :: String -> IO [File]
readDir dir = findRegularFiles dir >>= readFiles
    findRegularFiles = find always (fileType ==? RegularFile)
    readFiles paths = mapM readFile paths >>= return.zip paths

...and I would like to write the function readDir like this:
readDir :: String -> IO [File]
readDir = findRegularFiles >>= readFiles
  where ...

...but I get the error:
    Couldn't match expected type `IO [FilePath]'
                with actual type `[FilePath]'
    Expected type: IO [FilePath] -> String -> IO [File]
      Actual type: [FilePath] -> IO [File]
    In the second argument of `(>>=)', namely `readFiles'
    In the expression: findRegularFiles >>= readFiles

Can somebody please explain it?

It's not a big deal. I can keep the old version which works fine. My only
problem is that I thought I understood the monads better but apparently I
don't :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120204/1778a4db/attachment.htm>

More information about the Beginners mailing list