[Haskell-beginners] List Sorting and I/O

Lorenzo Isella lorenzo.isella at gmail.com
Tue Sep 14 05:40:55 EDT 2010

>> Finally, I would like to be able to save the two lists as plain text
>> files (no commas, no brackets).
>> I tried writeFile+Show, but this saves the lists exactly as printed on
>> screen (whereas I simply would like a text file showing a column of
>> numbers when opened by your favorite editor).
>> Many thanks
> One list as a column:
> writeFile "bar" $ unlines (map show list)
> A list as a space-separated sequence of numbers on one line:
> writeFile "bar" $ unwords (map show list)

Hi Daniel,
And thanks for your help. Your solution works, but it looks like that on 
my machine (an up-to-date desktop computer with plenty of ram) file 
writing is unusually slow [it looks like it takes more than 10 minutes 
to write a text file of a few megabites which comes from a long list].
I wonder if there is any way to speed up the process or it is an 
inherent limitation of lists (or I am making some mistake).


P.S.: the list is a list of lists, hence I use this function

save_vector_flat filename list = writeFile filename $ unlines (map show 
$ concat list)

More information about the Beginners mailing list