doesDirectoryExist and doesFileExist work on the
toplevel for ghci but they dont work in my code. for
example
Prelude> :l Sorter.hs
Compiling Sorter ( Sorter.hs, interpreted )
Ok, modules loaded: Sorter.
Sorter> doesDirectoryExist "/usr/include"
it :: Bool
Sorter> print it
True
it :: ()
this works fine.
now the relevant part of my code is
module Test ()
where
import Directory
foldrIO f s [] = do return s
foldrIO f s (x:xs) = do
p <- foldrIO f s xs
f x p
filterIO :: (a -> IO Bool) -> [a] -> IO [a]
filterIO p l = do
foldrIO (\x xs -> do
s <- p x
return (if s then x:xs else xs))
[] l
isDir = doesDirectoryExist
getDirs dir = do
d <- getDirectoryContents dir
p <- filterIO isDir d
return (filter (/= ".") (filter (/= "..") p))
and what happens is
Sorter> :l Test.hs -- test contains only the code i
gave above
Compiling Test ( Test.hs, interpreted )
Ok, modules loaded: Test.
Test> getDirs "/usr"
it :: [[Char]]
Test> print it
["bin","src"]
it :: ()
Test> getDirectoryContents "/usr"
it :: [FilePath]
Test> print it
[".","..","bin","include","lib","libdata","libexec","local","sbin","share","src","games","ports","X11R6","compat","obj","tmp","home","var","sup"]
it :: ()
Test> doesDirectoryExist "/usr/include"
it :: Bool
Test> print it
True
it :: ()
Test> doesDirectoryExist "/usr/libexec"
it :: Bool
Test> print it
True
it :: ()
Test> doesDirectoryExist "/usr/src"
it :: Bool
Test> print it
True
it :: ()
in the /usr dir only src and bin get recognized as dirs
even though everyone of the files in /usr is a dir. in
many dirs none of the subdirs are recognized. so far it
has consistently been recognizing the same subdirs in
each dir i test but i dont know if that means anything.
if you test each of them with doesDirectoryExist on the
toplevel of ghci each of them is recognized as a dir.
this problem also shows up if i compile it.
an analgous problem exists for doesFileExist.
i run freebsd 4.5 stable with ghc 5.02.2. if there is
anything i can do to help you fix this please let me
know at uglydaemon@shaw.ca