[Haskell-cafe] After `readFile`, why cannot i `writeFile` ?
Bill Atkins
watkins at alum.rpi.edu
Mon Jun 7 19:18:09 EDT 2010
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 <z_axis at 163.com> 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 busy (file is locked)
More information about the Haskell-Cafe
mailing list