IO recursion

Stefan Karrmann sk@mathematik.uni-ulm.de
Mon, 9 Apr 2001 09:42:54 +0200


mapple apple schrieb folgendes am Sat, Apr 07, 2001 at 02:36:50PM +1000:
> main :: IO ()
> main = do
>              putStr "Filename plz: "
>              file <- getLine
>              content <- readFile file
>              putStr ("1: " ++ read (show (head (lines content))))
>              and so on

Try:

number start [] = []
number start [line:lines] = [(show start) ++ ": " ++ line : number (start + 1) lines]

main = do
	putStr "Filename plz: "
	file <- getLine
	content <- readFile file
	putStr (unlines (number 1 (lines content)))

You should do most of the computations in the functional style and
not in the IO Monad.

-- 
Stefan Karrmann