[Haskell-cafe] file line operation perhaps need loop

2005-07-20 Thread Sun Yi Ming
Hello, I have two txt file,and i want to mix the two files line by line, e.g. $ cat url1.txt url1_1.line url1_2.line $ cat url2.txt url2_1.line url2_2.line and i want this file as result: $ cat aha.txt url1_1.line url2_1.line url1_2.line url2_2.line i first write

Re: [Haskell-cafe] file line operation perhaps need loop

2005-07-20 Thread yin
Sun Yi Ming wrote: Hello, Hello, this works fine, but i think if the two file are very big, and the readFile will consume too many mem.so i need to read the file line by line but stunned by the loop in IO Monad: main = do h1 - openFile url1.txt ReadMode h2 - openFile url2.txt ReadMode

Re: [Haskell-cafe] file line operation perhaps need loop

2005-07-20 Thread Arthur van Leeuwen
On Wed, Jul 20, 2005 at 02:27:36PM +0800, Sun Yi Ming wrote: Hello, I have two txt file,and i want to mix the two files line by line, e.g. $ cat url1.txt url1_1.line url1_2.line $ cat url2.txt url2_1.line url2_2.line and i want this file as result: $ cat aha.txt

Re: [Haskell-cafe] file line operation perhaps need loop

2005-07-20 Thread Bernard Pope
On Wed, 2005-07-20 at 14:27 +0800, Sun Yi Ming wrote: [snip] i first write this snippet of code: --- import System.IO mix :: [a] - [a] - [a] mix [] ys = ys mix xs [] = xs mix (x:xs) (y:ys) = [x,y] ++ mix xs ys f1 = do contents1 - readFile url1.txt contents2 - readFile

Re: [Haskell-cafe] file line operation perhaps need loop

2005-07-20 Thread Henning Thielemann
On Wed, 20 Jul 2005, Sun Yi Ming wrote: mix :: [a] - [a] - [a] mix [] ys = ys mix xs [] = xs mix (x:xs) (y:ys) = [x,y] ++ mix xs ys mix xs ys = concat (Data.List.transpose [xs,ys]) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] file line operation perhaps need loop

2005-07-20 Thread Sun Yi Ming
Arthur van Leeuwen [EMAIL PROTECTED] worte: Ah, but this is exactly where lazyness wins bigtime: a smart implementation of readFile will lazily read the actual file for as far as needed. Thus, reading with readFile will not read the entire file into memory at once. What will happen is that