listDirectory :: FilePath -> IO [FilePath]
listDirectory path = do
  bracket (Posix.openDirStream path)
          (Posix.closeDirStream)
          (\dirStream -> do
             let loop accumulator = do
                   itemPath <- Posix.readDirStream dirStream
                   if itemPath == ""
                     then return accumulator
                     else loop $ accumulator ++ [itemPath]
             loop [])
listDirectory :: FilePath -> IO [FilePath]
listDirectory path = do
  bracket (Posix.openDirStream path)
          (Posix.closeDirStream)
          (\dirStream -> do
             let loop accumulator = do
                   itemPath <- Posix.readDirStream dirStream
                   if itemPath == ""
                     then return accumulator
                     else loop $ accumulator ++ [itemPath]
             loop [])
listDirectory path = do
  bracket (Posix.openDirStream path)
          (Posix.closeDirStream)
          (\dirStream -> do
             let loop accumulator = do
                   itemPath <- Posix.readDirStream dirStream
                   if itemPath == ""
                     then return accumulator
                     else loop $ accumulator ++ [itemPath]
             loop [])