Haskell Listing Directories in Working Directory I've got this fairly simple program to print out each subdirectory of the working dir.

import System.Directory (listDirectory, doesDirectoryExist)

main = do
    dirs &lt;- getDirectories
    mapM_ putStrLn dirs

-- Get a list of directories within the working directory
getDirectories :: IO [FilePath]
getDirectories = do
    contents &lt;- listDirectory "." 
    fIO doesDirectoryExist contents

-- Filter a list with an IO predicate.
-- (In this use case, queries file system for directory status.)
fIO :: (a -&gt; IO Bool) -&gt; [a] -&gt; IO [a] 
fIO f [] = return []
fIO f (x:xs) = do
    matches &lt;- f x 
    rest &lt;- fIO f xs
    return $ (if matches then [x] else []) ++ rest


I also attempted this implementation of the fIO function, and I'm not sure if it's legitimately less clear or if it only appears that way to me because I'm not used to reading Haskell-style syntax yet.

fIO f (x:xs) = do
    matches &lt;- f x 
    fIO f xs &gt;&gt;= return . ((if matches then [x] else []) ++)


Critique Request

Being a Haskell newbie, I'm sure a professional would change some things about this implementation. I'm curious what sticks out as awkward, non-idiomatic, or opaque. I'm also curious which implementation of the two fIOs (if either) you would select, and why.
Instead of fIO f xs &gt;&gt;= return . ((if matches then [x] else []) ++), you can use &lt;$&gt;:

([x | matches] ++) &lt;$&gt; fIO f xs


Applicative style would allow you to compress all this yet further:

fIO f (x:xs) = (\matches -&gt; ([x | matches] ++)) &lt;$&gt; f xs &lt;*&gt; fIO f xs


But in the end:

fIO = filterM