on master help sign in
Added Prelude.File.writeFile
commit92bdae542e7e4f1ade0cbbe191b91dd89f0bf14e authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSun 1 Nov 2015, 12:18 (11 years ago) parentb1872fb
1 file changed+8−2
libs/prelude/Prelude/File.idr+8−2
libs/prelude/Prelude/File.idr+8−2
@@ -40,7 +40,6 @@ getFileError = do MkRaw err <- foreign FFI_C "idris_mkFileError"
4040 return err
4141
4242instance Show FileError where
43− show Success = "Success"
4443 show FileNotFound = "File Not Found"
4544 show PermissionDenied = "Permission Denied"
4645 show (GenericFileError errno) = strError errno
@@ -184,4 +183,11 @@ readFile fn = do Right h <- openFile fn Read
184183 readFile' h (contents ++ l)
185184 else return (Right contents)
186185
187−
186+||| Write a string to a file
187+writeFile : (filepath : String) -> (contents : String) ->
188+ IO (Either FileError ())
189+writeFile fn contents = do
190+ Right h <- openFile fn Write | Left err => return (Left err)
191+ Right () <- fwrite h contents | Left err => return (Left err)
192+ closeFile h
193+ return (Right ())