Hi Bill,
Each quote of the input is on a single line. I want to unwrap lines greater than 72 characters, i.e., break them into several lines each <= 72 characters, but I don't want to break up words. and I want to retain the blank lines. So, my output is correct except for the error message.
Michael
============ My input data ============
However mean your life is, meet it and live it: do not shun it and call it hard names. Cultivate poverty like a garden herb, like sage. Do not trouble yourself much to get new things, whether clothes or friends. Things do not change, we change. Sell your clothes and keep your thoughts. God will see that you do want society.
Men have become the tools of their tools.
I know of no more encouraging fact than the unquestioned ability of a man to elevate his life by conscious endeavor.
I once had a sparrow alight upon my shoulder for a moment, while I was hoeing in a village garden, and I felt that I was more distinguished by that circumstance that I should have been by any epaulet I could have worn.
-Thoreau
============ My output ============
unwrap: <stdin>: hGetLine: end of file <<<< here's my eof message
However mean your life is, meet it and live it: do not shun it and call
it hard names. Cultivate poverty like a garden herb, like sage. Do not
trouble yourself much to get new things, whether clothes or friends.
Things do not change, we change. Sell your clothes and keep your
thoughts. God will see that you do want society.
Men have become the tools of their tools.
I know of no more encouraging fact than the unquestioned ability of a
man to elevate his life by conscious endeavor.
I once had a sparrow alight upon my shoulder for a moment, while I was
hoeing in a village garden, and I felt that I was more distinguished by
that circumstance that I should have been by any epaulet I could have
worn.
-Thoreau
============ Your output ==========
However mean your life is, meet it and live it: do not shun it and call
it hard names. Cultivate poverty like a garden herb, like sage. Do not t
rouble yourself much to get new things, whether clothes or friends. Thin
gs do not change, we change. Sell your clothes and keep your thoughts. G
od will see that you do want society.
Men have become the tools of their tools.
I know of no more encouraging fact than the unquestioned ability of a ma
n to elevate his life by conscious endeavor.
I once had a sparrow alight upon my shoulder for a moment, while I was h
oeing in a village garden, and I felt that I was more distinguished by t
hat circumstance that I should have been by any epaulet I could have wor
n.
-Thoreau
===================================
--- On Fri, 8/13/10, Bill Atkins
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
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe