[Haskell-beginners] Help! Trapped in the IO Monad!
alexander.dunlap at gmail.com
Wed Jan 28 20:30:00 EST 2009
On Wed, Jan 28, 2009 at 5:18 PM, Erik de Castro Lopo
<mle+cl at mega-nerd.com> wrote:
> 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.
It seems like foldM ought to do what you want. Could you post some
more details please?
More information about the Beginners