IO recursion

Bernd Holzmüller holzmueller@ics-ag.de
Mon, 09 Apr 2001 09:39:05 +0200


Use may write: 

main = do
          putStr "Filename plz: "
          file <- getLine
          content <- readFile file
	  let linesWithNo = map (\(lineNo, s) -> show lineNo ++ ": " ++ s) (zip
[1..] (lines content))
	  mapM putStrLn linesWithNo

then:

main
Filename plz: lines.hs
1: main = do
2:           putStr "Filename plz: "
3:           file <- getLine
4:           content <- readFile file
5: 	  let linesWithNo = map (\(lineNo, s) -> show lineNo ++ ": " ++ s)
(zip [1..] (lines content))
6: 	  mapM putStrLn linesWithNo

Cheers, 
Bernd Holzmüller

mapple apple schrieb:
> 
> Hi everyone,
> 
> I'm not sure this is the place to ask, coz I hvn't join your mailing
> list. But anyway ..
> 
> Here's the case .. does anybody know 'bout IO recursion?
> ie. We've a file and we want to put a numberline
> 
> 1: 'first line'
> 2: 'second line'
> until n, where n is the last line
> 
> I know how to convert a file into a huge string using 'readFile'
> and I'm using the 'lines function' in the prelude.
> 
> That means i have a huge string like "\nHi mate\nHow r u?"
> using the helper function 'lines' i can do that by saying :
> 
> main :: IO ()
> main = do
>              putStr "Filename plz: "
>              file <- getLine
>              content <- readFile file
>              putStr ("1: " ++ read (show (head (lines content))))
>              and so on
> 
> that's not recursive function and will not work for all cases.
> So please .. if anyone knows how to do those things, let me know.
> 
> one more thing, does anybody know how to join the mailing list??
> 
> mapple apple
> mapple_83@hotmail.com
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
> 
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell