I have a text file with the following data:
3
7 4
2 4 6
8 5 9 3
I want to essentially extract this data and return it in the form:
["3", "7 4", "2 4 6", "8 5 9 3"]
I used readFile
to get the entire file as a single string, and then used lines to parse the individual line based on the '\n'
character. I tried doing this but the problem I'm getting is that readFile
returns IO String
, but I want String
instead. Here's the code:
readLines :: FilePath -> [String]
readLines str = do
file <- readFile str
let list = lines (file :: String)
list
How do I deal with this problem?