
8 Apr
2007
8 Apr
'07
11:11 p.m.
Albert Lee on 2007-04-09 10:46:14 +0800:
I want to ls the filenames of a directory.
[...]
and I write that in haskell:
----- import System.Posix import System.IO
main = do dp <- openDirStream "/" df <- readDirStream dp putStrLn df closeDirStream dp
------ It can print the first entry of the dir, but how can we list it all like the C prog? map ? list comperhension?
System.Posix is one way to do it, but you might find the functions in System.Directory easier to use - there's a function to get the directory contents as a list of strings. To print them out, you may want to look at one of the mapM functions.