You could also create a wrapper function that accepts [[String]] and let it deal with the inner lists. If it  is  pure function, then you can say Right r -> return (<your function> r). This would wrap the return value from the function in IO monad.

On Mon, Jan 24, 2011 at 3:44 PM, Shakthi Kannan <shakthimaan@gmail.com> wrote:
Hi,

I am trying to parse a .csv file and process the individual lines.
Here is some code snippet (based on RWH Chapter 16 [1]):

=== test.hs ===

import Text.ParserCombinators.Parsec
import System.Environment (getArgs)

parseCSV :: String -> Either ParseError [[String]]
parseCSV input = parse csvFile "(unknown)" input

main = do
   do c <- getContents
      case parse csvFile "(stdin)" c of
           Left e -> do putStrLn "Error parsing input:"
                        print e
           Right r -> mapM_ print r

=== END ===

Given an input file foo.csv:

a,b,c
d,e,f
g,h,i

and running the above test.hs using:

 $ runghc test.hs < foo.csv

I get the following output:

["a,b,c"]
["d,e,f"]
["g,h,i"]

Instead of using mapM_ print r, how can I obtain and pass each of the
above lists (for example, ["a,b,c"]) to another function for
processing?

Appreciate any inputs,

Thanks!

SK

[1] RWH. Using Parsec. http://book.realworldhaskell.org/read/using-parsec.html

--
Shakthi Kannan
http://www.shakthimaan.com

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners



--
Regards
Lakshmi Narasimhan T V