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

Andrew Wagner wagner.andrew at gmail.com
Tue Jan 27 23:12:07 EST 2009

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:

On Tue, Jan 27, 2009 at 11:07 PM, Erik de Castro Lopo
<mle+cl at mega-nerd.com<mle%2Bcl at 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090127/2d55812e/attachment.htm

More information about the Beginners mailing list