[Haskell-cafe] Unwrapping long lines in text files
michael rice
nowgate at yahoo.com
Fri Aug 13 21:38:46 EDT 2010
The program below takes a text file and unwraps all lines to 72 columns, but I'm getting an end of file message at the top of my output.
How do I lose the EOF?
Michael
====== unwrap.hs ======
main = do
line <- getLine
if null line
then do
putStrLn ""
main
else
do
printList (words line) 1
main
printList :: [String] -> Int -> IO ()
printList [] _ = do putStrLn ""
printList (w:[]) k = do
if k+(length w) <= 72
then do
putStrLn w
else do
putStrLn ""
putStrLn w
printList r@(w:ws) k = do
if k+(length w) <= 72
then do
putStr w
putStr " "
printList ws (k+(length w)+1)
else do
putStrLn ""
printList r 1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100813/d4cea93d/attachment.html
More information about the Haskell-Cafe
mailing list