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.
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
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
participants (3)
-
Bernd Holzmüller -
mapple apple -
Stefan Karrmann