
Hi, I try to parse csv file with Text.CSV, like this: import Text.CSV import System main = do [inpFileName] <- getArgs putStrLn ("Parsing "++inpFileName++"...") let result = parseCSVFromFile inpFileName print result === As a result I get: No instance for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) arising from a use of `print' Possible fix: add an instance declaration for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) === Question: How to add a Show instance for "(IO (Either Text.Parsec.Error.ParseError CSV)))" ? Thanks!

On Fri, Jun 17, 2011 at 12:00 PM, Dmitri O.Kondratiev
Hi, I try to parse csv file with Text.CSV, like this:
import Text.CSV import System
main = do [inpFileName] <- getArgs putStrLn ("Parsing "++inpFileName++"...") let result = parseCSVFromFile inpFileName print result
=== As a result I get:
No instance for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) arising from a use of `print' Possible fix: add an instance declaration for (Show (IO (Either Text.Parsec.Error.ParseError CSV)))
=== Question: How to add a Show instance for "(IO (Either Text.Parsec.Error.ParseError CSV)))" ?
Thanks!
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
I think what you want is:
main = do [inpFileName] <- getArgs putStrLn ("Parsing "++inpFileName++"...") result <- parseCSVFromFile inpFileName print result
Michael

On 06/17/2011 10:00 AM, Dmitri O.Kondratiev wrote:
Hi, I try to parse csv file with Text.CSV, like this:
import Text.CSV import System
main = do [inpFileName] <- getArgs putStrLn ("Parsing "++inpFileName++"...") let result = parseCSVFromFile inpFileName print result
=== As a result I get:
No instance for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) arising from a use of `print' Possible fix: add an instance declaration for (Show (IO (Either Text.Parsec.Error.ParseError CSV)))
=== Question: How to add a Show instance for "(IO (Either Text.Parsec.Error.ParseError CSV)))" ? Hi Dmitri,
you don't add a show instance for IO, but you "unwrap" the IO Monad first and then show the result. let result = parseCSVFromFile inpFileName should be: result <- parseCSVFromFile inpFileName -- Vincent

On Fri, Jun 17, 2011 at 1:04 PM, Vincent Hanquez
On 06/17/2011 10:00 AM, Dmitri O.Kondratiev wrote:
Hi, I try to parse csv file with Text.CSV, like this:
import Text.CSV import System
main = do [inpFileName] <- getArgs putStrLn ("Parsing "++inpFileName++"...") let result = parseCSVFromFile inpFileName print result
=== As a result I get:
No instance for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) arising from a use of `print' Possible fix: add an instance declaration for (Show (IO (Either Text.Parsec.Error.ParseError CSV)))
=== Question: How to add a Show instance for "(IO (Either Text.Parsec.Error.ParseError CSV)))" ?
Hi Dmitri,
you don't add a show instance for IO, but you "unwrap" the IO Monad first and then show the result.
let result = parseCSVFromFile inpFileName
should be:
result <- parseCSVFromFile inpFileName
-- Vincent
Thanks everybody! This is how I solved it: import Text.CSV import Data.Either import System import Data.List main = do [inpFileName] <- getArgs putStrLn ("Parsing "++inpFileName++"...") result <- parseCSVFromFile inpFileName let errors = lefts [result] let csvL = rights [result] print "CSV list" print csvL print "Errors" print errors putStrLn "All done."

Maybe you can directly distinguish if the parser returned an error (Left) or
not (Right), instead of using lefts and rights:
import Text.CSV
import Data.Either
import System
import Data.List
main = do
[inpFileName] <- getArgs
putStrLn ("Parsing "++inpFileName++"...")
result <- parseCSVFromFile inpFileName
case result of
Left error -> do print "Parse error: "
print error
Right csv -> print csvL
putStrLn "All done."
2011/6/17 Dmitri O.Kondratiev
On Fri, Jun 17, 2011 at 1:04 PM, Vincent Hanquez
wrote: On 06/17/2011 10:00 AM, Dmitri O.Kondratiev wrote:
Hi, I try to parse csv file with Text.CSV, like this:
import Text.CSV import System
main = do [inpFileName] <- getArgs putStrLn ("Parsing "++inpFileName++"...") let result = parseCSVFromFile inpFileName print result
=== As a result I get:
No instance for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) arising from a use of `print' Possible fix: add an instance declaration for (Show (IO (Either Text.Parsec.Error.ParseError CSV)))
=== Question: How to add a Show instance for "(IO (Either Text.Parsec.Error.ParseError CSV)))" ?
Hi Dmitri,
you don't add a show instance for IO, but you "unwrap" the IO Monad first and then show the result.
let result = parseCSVFromFile inpFileName
should be:
result <- parseCSVFromFile inpFileName
-- Vincent
Thanks everybody! This is how I solved it:
import Text.CSV import Data.Either import System import Data.List
main = do [inpFileName] <- getArgs putStrLn ("Parsing "++inpFileName++"...") result <- parseCSVFromFile inpFileName let errors = lefts [result] let csvL = rights [result] print "CSV list" print csvL print "Errors" print errors putStrLn "All done."
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Mon, Jun 20, 2011 at 7:30 PM, Alejandro Serrano Mena
Maybe you can directly distinguish if the parser returned an error (Left) or not (Right), instead of using lefts and rights:
import Text.CSV import Data.Either import System import Data.List
main = do [inpFileName] <- getArgs putStrLn ("Parsing "++inpFileName++"...") result <- parseCSVFromFile inpFileName case result of Left error -> do print "Parse error: " print error Right csv -> print csvL putStrLn "All done."
Yes, you right, this is better, then printing empty error list.
2011/6/17 Dmitri O.Kondratiev
On Fri, Jun 17, 2011 at 1:04 PM, Vincent Hanquez
wrote: On 06/17/2011 10:00 AM, Dmitri O.Kondratiev wrote:
Hi, I try to parse csv file with Text.CSV, like this:
import Text.CSV import System
main = do [inpFileName] <- getArgs putStrLn ("Parsing "++inpFileName++"...") let result = parseCSVFromFile inpFileName print result
=== As a result I get:
No instance for (Show (IO (Either Text.Parsec.Error.ParseError CSV))) arising from a use of `print' Possible fix: add an instance declaration for (Show (IO (Either Text.Parsec.Error.ParseError CSV)))
=== Question: How to add a Show instance for "(IO (Either Text.Parsec.Error.ParseError CSV)))" ?
Hi Dmitri,
you don't add a show instance for IO, but you "unwrap" the IO Monad first and then show the result.
let result = parseCSVFromFile inpFileName
should be:
result <- parseCSVFromFile inpFileName
-- Vincent
Thanks everybody! This is how I solved it:
import Text.CSV import Data.Either import System import Data.List
main = do [inpFileName] <- getArgs putStrLn ("Parsing "++inpFileName++"...") result <- parseCSVFromFile inpFileName let errors = lefts [result] let csvL = rights [result] print "CSV list" print csvL print "Errors" print errors putStrLn "All done."
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (4)
-
Alejandro Serrano Mena
-
Dmitri O.Kondratiev
-
Michael Snoyman
-
Vincent Hanquez