My mistake. I did not read the Text.CSV.ByteString document carefully. parseCSV requires a strict ByteString, but I was feeding a lazy one.
Have a good weekend!
Hong
I have the following code:
$$$$$$$$
module Main where
import System.Environment (getArgs)
import Text.CSV.ByteString
import qualified Data.ByteString.Lazy.Char8 as L
main = do
[args] <- getArgs
file <- L.readFile args
let result = parseCSV file
case result of
Nothing -> putStrLn "Error when parsing!"
Just contents -> do
putStrLn "parsing OK!"
-- map_header_records contents
$$$$$$$$
which yielded the error as follows:
Couldn't match expected type `Data.ByteString.Internal.ByteString'
against inferred type `L.ByteString'
In the first argument of `parseCSV', namely `file'
In the expression: parseCSV file
In the definition of `result': result = parseCSV file
readFile in the Data.ByteString.Lazy.Char8 module returns ByteString type. Since the module is qualified as L, L.readFile returns L.ByteString. But parseCSV expects a ByteString. Sometimes this is annoying, because it makes type matching difficult (at least for me, a beginner). I really wish Haskell can intelligently treat L.ByteString, M.ByteString, and whatever X.ByteString the same as ByteString, and match them.
Can someone tell me how to solve the above problem?
Thanks,
Hong