This is what I've done;
import Control.Applicative import Control.Monad import qualified System.Directory as SD main = do files <- SD.getDirectoryContents =<< SD.getCurrentDirectory exes <- filterM (liftA SD.executable <$> SD.getPermissions) files print exes
This works fine, but I can't help feeling that this code is somewhat redundant --- with
=<< all present at once, things seem unnecessarily complicated.
How can I improve this piece of code?
For a quick reference:
SD.getCurrentDirectory :: IO FilePath SD.getDirectoryContents :: FilePath -> IO [FilePath] SD.executable :: Permissions -> Bool SD.getPermissions :: FilePath -> IO Permissions
and I want to filter the contents of the current directory based on its being executable or not.