[Haskell-beginners] Help for type matching
hyangfji at gmail.com
Fri Nov 6 16:47:06 EST 2009
I have the following code:
module Main where
import System.Environment (getArgs)
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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners