[Haskell-beginners] Reading Multiple Files and Iterate Function
Application
Lorenzo Isella
lorenzo.isella at gmail.com
Mon Oct 11 10:56:58 EDT 2010
Dear All,
Another I/O question.
Let us say that you are given a list of files file1.dat,
file2.dat...file10.dat and so on (i.e. every file is indexed by a number
and every file is a single column where every entry is a string without
spaces).
In the snippet below I read file1.dat, convert it to a list and then
print out its length.
Now, how can I iterate the process on file1.dat, file2.dat and file3.dat
and store the lengths in a list?
I would like to map the file reading and following operations on the
list [1,2.3], but that is giving me a headache.
It is relatively easy to create the file name
filename="file"++(show i)++".dat" , for i=1,2,3
but it the the iteration part that is giving me troubles.
Any suggestion is appreciated.
Cheers
Lorenzo
-- #####################################################################
import Data.Ord
import Data.List
main :: IO ()
main = do
list_t <- readFile "file1.dat"
let list = lines list_t
let b = length list
putStrLn "length of list is, "
print b
More information about the Beginners
mailing list