Hi Erik,
The short answer to your question is to not write splitDirFile to operate on FilePaths, but on some wrapper around FilePaths that also contain information about whether each path is to a directory or a file. Then you can call splitDirFile purely. For the long, but very good, answer, see RWH, where they discuss this very specifically: http://book.realworldhaskell.org/read/io-case-study-a-library-for-searching-the-filesystem.html

On Tue, Jan 27, 2009 at 11:07 PM, Erik de Castro Lopo <mle+cl@mega-nerd.com> wrote:
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.
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners