[Haskell-beginners] Reading in the contents of a variable number of files

Tim Perry perry2of5 at yahoo.com
Tue Mar 16 17:10:46 EDT 2010

I need to read in and then combine a variable number of files. I am 
trying to figure out how to get the contents of all the files into an 

let fileContentsArray = getData ["dataFile1.txt", 

getData :: [String] -> [String]
getData [] = []
getData (f:files) = do 
<- readFile f
                       fileData : (getData files)

I figured I could use readFile to open the files. But, I need to use 
<- to get the data out of the IO Action and into a value. I thought I could write a function like the following, but I'm getting no-where. I 
suspect I'm missing something basic about IO in Haskell. Can anybody 
point me to a good resource....


More information about the Beginners mailing list