[Haskell-beginners] too lazy parsing?
k.bleijenberg at lijbrandt.nl
Mon Feb 4 11:50:24 CET 2013
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
let res = parse (many (string "blah")) "" cont
case res of
(Left err) -> hPutStrLn hOut $ "Error: " ++
(Right goodRes) -> mapM_ (hPutStrLn hOut)
main = do
hOut <- openFile "outp.txt" WriteMode
mapM (parseFile hOut) ["inp.txt"]
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
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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners