My mistake. I did not read the Text.CSV.ByteString document carefully. parseCSV requires a strict ByteString, but I was feeding a lazy one.<br><br>Have a good weekend!<br><br>Hong<br><br><div class="gmail_quote">On Fri, Nov 6, 2009 at 3:47 PM, Hong Yang <span dir="ltr"><<a href="mailto:hyangfji@gmail.com">hyangfji@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I have the following code:<br><br>$$$$$$$$<br>module Main where<br><br>import System.Environment (getArgs)<br>
import Text.CSV.ByteString<br>import qualified Data.ByteString.Lazy.Char8 as L<br><br>main = do<br> [args] <- getArgs<br>
file <- L.readFile args<br> let result = parseCSV file<br> case result of<br> Nothing -> putStrLn "Error when parsing!"<br> Just contents -> do<br> putStrLn "parsing OK!"<br>
-- map_header_records contents<br>$$$$$$$$<br><br>which yielded the error as follows:<br><br> Couldn't match expected type `Data.ByteString.Internal.ByteString'<br> against inferred type `L.ByteString'<br>
In the first argument of `parseCSV', namely `file'<br> In the expression: parseCSV file<br> In the definition of `result': result = parseCSV file<br><br>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.<br>
<br>Can someone tell me how to solve the above problem?<br><br>Thanks,<br><font color="#888888"><br>Hong<br>
</font></blockquote></div><br>