[Haskell-beginners] Convert String to List/Array of Numbers

Lorenzo Isella lorenzo.isella at gmail.com
Wed Sep 8 09:31:19 EDT 2010


Dear All,
I must be stuck on something pretty basic (I am struggling badly with I/O).
Let us assume you have a rather simple file mydata.dat (3 columns of 
integer numbers), see below.



1246191122 1336 1337
1246191142 1336 1337
1246191162 1336 1337
1246191182 1336 1337
1246191202 1336 1337
1246191222 1336 1337
1246191242 1336 1337
1246191262 1336 1337
1246191282 1336 1337
1246191302 1336 1337
1246191322 1336 1337
1246191342 1336 1337
1246191362 1336 1337
1246191382 1336 1337
1246191402 1336 1337
1246191422 1336 1337

Now, my intended pipeline could be

read file as string--> convert to list of integers-->pass it to hmatrix 
(or try to convert it into a matrix/array).
Leaving aside the last step, I can easily do something like

let dat=readFile "mydata.dat"


in the interactive shell and get a string, but I am having problems in 
converting this to a list or anything more manageable (where every entry 
is an integer number i.e. something which can be summed, subtracted 
etc...). Ideally even a list where every entry is a row (a list in 
itself) would do.
I found online this suggestion
http://bit.ly/9jv1WG
but I am not sure if it really applies to this case.
Many thanks

Lorenzo


More information about the Beginners mailing list