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

Erik de Castro Lopo mle+cl at mega-nerd.com
Tue Jan 27 23:07:01 EST 2009


Hi all,

I have a list of entries for a directory (FilePaths) and I'd like to
partition them into files and directories using Data.List.partition:

    partition :: [a] -> ([a], [a])

Now, one solution is to use unsafePerformIO:

    splitDirFile :: [FilePath] -> ([FilePath], [FilePath])
    splitDirFile paths = do
        partition (\p -> unsafePerformIO (doesDirectoryExist p)) paths

Two questions:

  a) Is it possible to do this without invoking unsafePerformIO? Ie with
     a function signature of say:

         partition :: [FilePath] -> IO ([FilePath], [FilePath])

  b) Exactly how unsafe is the unsafePerformIO version?

Erik
-- 
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
The main confusion about C++ is that its practitioners think
it is simultaneously a  high and low level language when in
reality it is good at neither.


More information about the Beginners mailing list