Help for type matching

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Help for type matching

Hong Yang-2
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/0cea5c2f/attachment-0001.html
Reply | Threaded
Open this post in threaded view
|

Re: Help for type matching

Hong Yang-2
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 <[hidden email]> 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