--- /dev/null
+definition module SimpleFileIO\r
+\r
+import StdFile, StdOverloaded, StdMaybe\r
+\r
+// 1.\r
+//readFile :: String *env -> (Maybe String, *env) | FileSystem env\r
+//writeFile :: String String *env -> (Bool, *env) | FileSystem env\r
+\r
+// 2.\r
+readLines :: String *env -> (Maybe [String],*env) | FileSystem env\r
+//writeLines :: String [String] *env -> (Bool, *env) | FileSystem env\r
+\r
+// 3.\r
+//mapFile :: String String (a -> b) *env -> (Bool, *env) | FileSystem env & ... a & ... b\r
--- /dev/null
+implementation module SimpleFileIO\r
+\r
+import StdEnv, StdFile, StdOverloaded, StdMaybe\r
+\r
+// 1.\r
+readFile :: String *env -> (Maybe String, *env) | FileSystem env\r
+readFile s env\r
+# (ss, env) = readLines s env\r
+| ss == Nothing = (Nothing, env)\r
+| otherwise = (Just (foldl (+++) "" (fromJust ss)), env)\r
+\r
+writeFile :: String String *env -> (Bool, *env) | FileSystem env\r
+writeFile fn s env\r
+# (ok, outfile, env) = fopen fn FWriteText env\r
+| not ok = (False, env)\r
+# outfile = fwrites s outfile\r
+# (ok, env) = fclose outfile env\r
+| otherwise = (ok, env)\r
+\r
+// 2.\r
+readLines :: String *env -> (Maybe [String],*env) | FileSystem env\r
+readLines s env\r
+# (ok, infile, env) = sfopen s FReadText env\r
+| not ok = (Nothing, env)\r
+| otherwise = (Just (fst (readLines` infile)), env)\r
+where\r
+ readLines` :: File -> ([String], File)\r
+ readLines` file \r
+ | sfend file = ([], file)\r
+ # (line, file) = sfreadline file\r
+ # (ss, file) = readLines` file\r
+ | otherwise = ([line : ss], file)\r
+\r
+writeLines :: String [String] *env -> (Bool, *env) | FileSystem env\r
+writeLines fn ss env = writeFile fn (foldl (+++) "" [s +++ "\n" \\ s <- ss]) env\r
+\r
+// 3.\r
+//mapFile :: String String (a -> b) *env -> (Bool, *env) | FileSystem env & ... a & ... b\r
+\r