[Haskell-beginners] Processing individual csv line

lakshminaras2002 at gmail.com lakshminaras2002 at gmail.com
Mon Jan 24 13:12:20 CET 2011


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 at 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Regards
Lakshmi Narasimhan T V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110124/9e3cc69d/attachment.htm>


More information about the Beginners mailing list