69278
|
1 |
{- generated by Isabelle -}
|
|
2 |
|
|
3 |
{- Title: Tools/Haskell/File.hs
|
|
4 |
Author: Makarius
|
|
5 |
LICENSE: BSD 3-clause (Isabelle)
|
|
6 |
|
69280
|
7 |
File-system operations.
|
|
8 |
|
|
9 |
See also "$ISABELLE_HOME/src/Pure/General/file.ML".
|
69278
|
10 |
-}
|
|
11 |
|
|
12 |
module Isabelle.File (setup, read, write, append) where
|
|
13 |
|
|
14 |
import Prelude hiding (read)
|
|
15 |
import System.IO (IO)
|
|
16 |
import qualified System.IO as IO
|
|
17 |
|
|
18 |
setup :: IO.Handle -> IO ()
|
|
19 |
setup h = do
|
|
20 |
IO.hSetEncoding h IO.utf8
|
|
21 |
IO.hSetNewlineMode h IO.noNewlineTranslation
|
|
22 |
|
|
23 |
read :: IO.FilePath -> IO String
|
|
24 |
read path =
|
|
25 |
IO.withFile path IO.ReadMode (\h ->
|
|
26 |
do setup h; IO.hGetContents h >>= \s -> length s `seq` return s)
|
|
27 |
|
|
28 |
write :: IO.FilePath -> String -> IO ()
|
|
29 |
write path s =
|
|
30 |
IO.withFile path IO.WriteMode (\h -> do setup h; IO.hPutStr h s)
|
|
31 |
|
|
32 |
append :: IO.FilePath -> String -> IO ()
|
|
33 |
append path s =
|
|
34 |
IO.withFile path IO.AppendMode (\h -> do setup h; IO.hPutStr h s)
|