[Haskell-beginners] Help! Trapped in the IO Monad!

Erik de Castro Lopo mle+cl at mega-nerd.com
Wed Jan 28 20:18:23 EST 2009

Alexander Dunlap wrote:

> You can do (something like; this is untested)
> splitDirFile :: [FilePath] -> IO ([FilePath],[FilePath])
> splitDirFile [] = return ([],[])
> splitDirFile (f:fs) = do
>   (yess,nos) <- splitDirFile fs
>   exists <- doesDirectoryExist f
>   return $ if exists
>     then (f:yess,nos)
>     else (yess,f:nos)

Untested, but seems to work perfectly :-). Thanks.

However, that brings me to the next stage where again I'm trapped.
I would like to do a foldl' on a function that returns IO [FilePath].

I tried using Control.Monad.foldM, but then I end up with a function
taht return :

   IO (IO ([FilePath]))

which doesn't work :-).

It seems pretty obvious that I could implement a recursion like
Alexander did above for splitDirFile but I was wondering if there
was a more general solution.

Erik de Castro Lopo
Heisenbugs - The bugs that go away when you turn on debugging.

More information about the Beginners mailing list