I have the following code which works fine:<br><br><div style="margin-left:40px">type File = (String, String) --name and content<br><br>readDir :: String -> IO [File]<br>readDir dir = findRegularFiles dir >>= readFiles<br>
where<br> findRegularFiles = find always (fileType ==? RegularFile)<br> readFiles paths = mapM readFile paths >>= return.zip paths<br></div><br>...and I would like to write the function readDir like this:<br>
<div style="margin-left:40px">readDir :: String -> IO [File]<br>
readDir = findRegularFiles >>= readFiles<br> where ...<br></div><br>...but I get the error:<br><div style="margin-left:40px">grep.hs:46:32:<br> Couldn't match expected type `IO [FilePath]'<br> with actual type `[FilePath]'<br>
Expected type: IO [FilePath] -> String -> IO [File]<br> Actual type: [FilePath] -> IO [File]<br> In the second argument of `(>>=)', namely `readFiles'<br> In the expression: findRegularFiles >>= readFiles<br>
</div><br>Can somebody please explain it?<br><br>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 :)<br>