Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  too lazy parsing? (Kees Bleijenberg)


----------------------------------------------------------------------

Message: 1
Date: Mon, 4 Feb 2013 11:50:24 +0100
From: "Kees Bleijenberg" <[email protected]>
Subject: [Haskell-beginners] too lazy parsing?
To: <[email protected]>
Message-ID: <000601ce02c5$6f6d73e0$4e485ba0$@[email protected]>
Content-Type: text/plain; charset="us-ascii"

module Main where 

 

import Text.ParserCombinators.Parsec (many,many1,string, Parser, parse)

import System.IO (IOMode(..),hClose,openFile,hGetContents,hPutStrLn)

 


parseFile hOut fn = do

                        handle <- openFile fn ReadMode

                        cont <- hGetContents handle


                        print cont

                        let res = parse (many (string "blah")) "" cont

                        hClose handle                    

                        case res of

                            (Left err) -> hPutStrLn hOut $ "Error: " ++
(show err)

                            (Right goodRes) -> mapM_ (hPutStrLn hOut)
goodRes                         

                 

main = do   

            hOut <- openFile "outp.txt" WriteMode

            mapM (parseFile hOut) ["inp.txt"]

            hClose hOut

 

I'am writing a program that parses a lot of files. Above is the simplest
program I can think of that demonstrates my problem.

The program above parses inp.txt.  Inp.txt has only the word blah in it.
The output is saved in outp.txt. This file contains the word blah after
running the program. if I comment out the line 'print cont' nothing is saved
in outp.txt.  

If I comment out 'print cont' and replace many with many1 in the following
line, it works again?

Can someone explain to me what is going  on?

 

Kees

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130204/b99d96be/attachment-0001.htm>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 56, Issue 6
****************************************

Reply via email to