@@ -152,11 +152,21 @@ fopen : String -> String -> IO File;
152fopen f m = do { h <- do_fopen f m;
152fopen f m = do { h <- do_fopen f m;
153 return (FHandle h); };
153 return (FHandle h); };
155+data Mode = Read | Write | ReadWrite;
157+openFile : String -> Mode -> IO File;
158+openFile f m = fopen f (modeStr m) where {
159+ modeStr : Mode -> String;
161+ modeStr Write = "w";
162+ modeStr ReadWrite = "r+";
155do_fclose : Ptr -> IO ();
165do_fclose : Ptr -> IO ();
156do_fclose h = mkForeign (FFun "fileClose" [FPtr] FUnit) h;
166do_fclose h = mkForeign (FFun "fileClose" [FPtr] FUnit) h;
158−fclose : File -> IO ();
168+closeFile : File -> IO ();
159−fclose (FHandle h) = do_fclose h;
169+closeFile (FHandle h) = do_fclose h;
161do_fread : Ptr -> IO String;
171do_fread : Ptr -> IO String;
162do_fread h = mkForeign (FFun "freadStr" [FPtr] FString) h;
172do_fread h = mkForeign (FFun "freadStr" [FPtr] FString) h;
@@ -177,6 +187,23 @@ feof : File -> IO Bool;
177feof (FHandle h) = do { eof <- do_feof h;
187feof (FHandle h) = do { eof <- do_feof h;
178 return (not (eof == 0)); };
188 return (not (eof == 0)); };
180−
190+while : |(test : IO Bool) -> |(body : IO ()) -> IO ();
181−
191+while t b = do { v <- t;
192+ if v then (do { b; while t b; }) else return (); };
194+readFile : String -> IO String;
195+readFile fn = do { h <- openFile fn Read;
196+ c <- readFile' h "";
201+ readFile' : File -> String -> IO String;
202+ readFile' h contents =
204+ if (not x) then (do { l <- fread h;
205+ readFile' h (contents ++ l);
207+ else (return contents); };