Re: [Haskell-cafe] After `readFile`, why cannot i `writeFile` ?

2010-06-07 Thread Bill Atkins
BTW, "\n -> show n" is equivalent to "show" . On Monday Jun 7, 2010, at 8:37 PM, zaxis wrote: >> Yes, and i can use appendFile too. >> >> appendFile "ssqHitNum.txt" $ unwords $ [no] ++ map (\n -> show n) hitNum >> ++ ["\n"] > ___ Haskell-Cafe mailing

Re: [Haskell-cafe] After `readFile`, why cannot i `writeFile` ?

2010-06-07 Thread zaxis
Bill Atkins-6 wrote: > > readFile reads the file lazily so it isn't closed until the entire > contents have been consumed. > > Try System.IO.Strict.readFile, which will read the entire file at once. > Yes, and i can use appendFile too. > > appendFile "ssqHitNum.txt" $ unwords $ [no] ++ map (

Re: [Haskell-cafe] After `readFile`, why cannot i `writeFile` ?

2010-06-07 Thread Bill Atkins
readFile reads the file lazily so it isn't closed until the entire contents have been consumed. Try System.IO.Strict.readFile, which will read the entire file at once. zaxis writes: > hitSSQ :: String -> [Int] -> IO () > hitSSQ no hitNum = do >let newNum = unwords $ [no] ++ map (\n -> show

Re: [Haskell-cafe] After `readFile`, why cannot i `writeFile` ?

2010-06-07 Thread Ivan Lazar Miljenovic
zaxis writes: > hitSSQ :: String -> [Int] -> IO () > hitSSQ no hitNum = do > let newNum = unwords $ [no] ++ map (\n -> show n) hitNum > hitNums <- fmap lines $ readFile "test.txt" > writeFile "test.txt" $ unlines $ hitNums ++ [newNum] > > *** Exception: test.txt: openFile: resource bu

[Haskell-cafe] After `readFile`, why cannot i `writeFile` ?

2010-06-07 Thread zaxis
hitSSQ :: String -> [Int] -> IO () hitSSQ no hitNum = do let newNum = unwords $ [no] ++ map (\n -> show n) hitNum hitNums <- fmap lines $ readFile "test.txt" writeFile "test.txt" $ unlines $ hitNums ++ [newNum] *** Exception: test.txt: openFile: resource busy (file is locked) Sincer