Lets say I have a file
8 [[1,2,3,4],[1,2]]
with number and list of lists in it.
This code allow me to read all line or n-th element from it.
import System.IO
main = do
x <- openFile "file.txt" ReadMode
cont <- hGetContents x
let fLines = lines cont
let numb = fLines !! 0 !! 0
print numb
here numb is '8'.
How can I get integer 8 from numb without using other libraries?
And is there a possibility to read list of lists and use it as list of lists?
Or should I better write each list in a new row, and read them row by row and add to empty list?
Maybe it's a stupid question, but I didn't find any example of doing something like that on internet.
UPDATE
Thanks to Fractal answer I've managed to write this
rList :: String -> [[Int]]
rList = read
which is working for list of lists!
However, when I cant make it work with single Int.
into :: String -> Int
into = read
Don't know why, but it doesn't work for numb T_T
UPDATE 2
Ok, it was kinda stupid. numb is Char here, so to make it work it will be enough to write
print (into [numb])
Thank you all for answers.
flineswith!!, it might be better to split at whitespace withwords. That way it is more flexible, and you won't have to convert the leadingCharback to aString.