@@ -141,3 +141,42 @@ print = putStrLn . show;
141141readLine : IO String;
142142readLine = mkForeign (FFun "readStr" Nil FString);
143143
144+---- some basic file handling
145+
146+data File = FHandle Ptr;
147+
148+do_fopen : String -> String -> IO Ptr;
149+do_fopen f m = mkForeign (FFun "fileOpen" [FString, FString] FPtr) f m;
150+
151+fopen : String -> String -> IO File;
152+fopen f m = do { h <- do_fopen f m;
153+ return (FHandle h); };
154+
155+do_fclose : Ptr -> IO ();
156+do_fclose h = mkForeign (FFun "fileClose" [FPtr] FUnit) h;
157+
158+fclose : File -> IO ();
159+fclose (FHandle h) = do_fclose h;
160+
161+do_fread : Ptr -> IO String;
162+do_fread h = mkForeign (FFun "freadStr" [FPtr] FString) h;
163+
164+fread : File -> IO String;
165+fread (FHandle h) = do_fread h;
166+
167+do_fwrite : Ptr -> String -> IO ();
168+do_fwrite h s = mkForeign (FFun "fputStr" [FPtr, FString] FUnit) h s;
169+
170+fwrite : File -> String -> IO ();
171+fwrite (FHandle h) s = do_fwrite h s;
172+
173+do_feof : Ptr -> IO Int;
174+do_feof h = mkForeign (FFun "feof" [FPtr] FInt) h;
175+
176+feof : File -> IO Bool;
177+feof (FHandle h) = do { eof <- do_feof h;
178+ return (not (eof == 0)); };
179+
180+
181+
182+