src/Pure/General/file.ML
changeset 28051 56e3a695434f
parent 28050 7cef47b53feb
child 28496 4cff10648928
--- a/src/Pure/General/file.ML	Thu Aug 28 20:19:45 2008 +0200
+++ b/src/Pure/General/file.ML	Thu Aug 28 20:29:40 2008 +0200
@@ -151,13 +151,14 @@
 fun fold_lines f path a = open_input (fn file =>
   let
     val split = split_last o String.fields (fn c => str c = "\n");
-    fun read buf x =
+    fun read buf =
       (case split (TextIO.input file) of
-        ([], "") => (case Buffer.content buf of "" => x | line => f line x)
-      | ([], rest) => read (Buffer.add rest buf) x
+        ([], "") => (case Buffer.content buf of "" => I | line => f line)
+      | ([], rest) => read (Buffer.add rest buf)
       | (line :: lines, rest) =>
-          read_rest (lines, rest) (f (Buffer.content (Buffer.add line buf)) x))
-    and read_rest (lines, rest) x = read (Buffer.add rest Buffer.empty) (fold f lines x);
+          f (Buffer.content (Buffer.add line buf))
+          #> fold f lines
+          #> read (Buffer.add rest Buffer.empty));
   in read Buffer.empty a end) path;
 
 val read = open_input TextIO.inputAll;