Maybe you can directly distinguish if the parser returned an error (Left) or not (Right), instead of using lefts and rights:<div><br></div><div>import Text.CSV<br>import Data.Either<br>import System<br>import Data.List<div class="im">
<br>main = do<br> [inpFileName] <- getArgs<br> putStrLn ("Parsing "++inpFileName++"...")<br></div> result <- parseCSVFromFile inpFileName</div><div> case result of</div><div> Left error -> do print "Parse error: "</div>
<div> print error</div><div> Right csv -> print csvL</div><div> putStrLn "All done."<br><br><div class="gmail_quote">2011/6/17 Dmitri O.Kondratiev <span dir="ltr"><<a href="mailto:dokondr@gmail.com">dokondr@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5"><br><br><div class="gmail_quote">On Fri, Jun 17, 2011 at 1:04 PM, Vincent Hanquez <span dir="ltr"><<a href="mailto:tab@snarc.org" target="_blank">tab@snarc.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div>On 06/17/2011 10:00 AM, Dmitri O.Kondratiev wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
I try to parse csv file with Text.CSV, like this:<br>
<br>
import Text.CSV<br>
import System<br>
<br>
main = do<br>
[inpFileName] <- getArgs<br>
putStrLn ("Parsing "++inpFileName++"...")<br>
let result = parseCSVFromFile inpFileName<br>
print result<br>
<br>
<br>
=== As a result I get:<br>
<br>
No instance for (Show<br>
(IO (Either Text.Parsec.Error.ParseError CSV)))<br>
arising from a use of `print'<br>
Possible fix:<br>
add an instance declaration for<br>
(Show (IO (Either Text.Parsec.Error.ParseError CSV)))<br>
<br>
=== Question:<br>
How to add a Show instance for "(IO (Either Text.Parsec.Error.ParseError CSV)))" ?<br>
</blockquote></div></div>
Hi Dmitri,<br>
<br>
you don't add a show instance for IO, but you "unwrap" the IO Monad first and then show the result.<br>
<br>
let result = parseCSVFromFile inpFileName<br>
<br>
should be:<br>
<br>
result <- parseCSVFromFile inpFileName<br>
<br>
-- <br><font color="#888888">
Vincent<br>
</font></blockquote></div><br></div></div>Thanks everybody! This is how I solved it:<br><br clear="all">import Text.CSV<br>import Data.Either<br>import System<br>import Data.List<div class="im"><br><br>main = do<br> [inpFileName] <- getArgs<br>
putStrLn ("Parsing "++inpFileName++"...")<br></div> result <- parseCSVFromFile inpFileName<br> let errors = lefts [result]<br> let csvL = rights [result]<br> print "CSV list"<br>
print csvL<br> print "Errors"<br> print errors<br> putStrLn "All done."<br><br>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>