The error has nothing to do with parsec or attoparsec. The line the error message points to is not an IO
action, so it causes the error when you try to use it as one:
main = do
handle <- openFile "C:\\Users\\ivan\\Downloads\\0005.HK.csv" ReadMode
contents <- hGetContents handle
let allLines = lines contents
map (\line -> quoteParser line) allLines -- <== This is not an IO action
--putStr contents
hClose handl
You ignore the result of the map
call. You should store it in a variable with let
, like you do with the result of lines
.
The second error is because you are trying to use Text
as String
which are different types, even though they both represent ordered collections of characters (they also have different internal representations). You can convert between the two types with pack
and unpack
: http://hackage.haskell.org/package/text/docs/Data-Text.html#g:5
Also, you should always explicitly give main
the type signature main :: IO ()
. It can sometimes lead to subtle problems if you don't.
As other people have said, though, you should probably use a csv parser package.