[Haskell-beginners] Re: Help for type matching

Hong Yang hyangfji at gmail.com
Fri Nov 6 18:57:47 EST 2009


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

On Fri, Nov 6, 2009 at 3:47 PM, Hong Yang <hyangfji at gmail.com> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20091106/5814097b/attachment.html


More information about the Beginners mailing list