是否可以对该辅助功能进行参数设置以接受TextIO.closeOut outstream
和readFileList xs outstream n
作为输入?还是我必须在TextIO中使用该append函数来拥有一个不太丑陋的函数体?是否可以匹配它们的类型?
两个主体基本相同,唯一的区别是在NONE情况下,第二个返回函数。
fun readFileList (x::xs) outstream n =
case xs of
[] => (let
val instream = TextIO.openIn x
val readline = TextIO.inputLine instream
fun aux readline n =
case readline of
NONE => (TextIO.closeIn instream; TextIO.closeOut outstream)
| SOME s => (TextIO.output(outstream, (getLineWriteCode s n));
aux (TextIO.inputLine instream) (n + 1))
in
aux readline n
end)
| _ => (let
val instream = TextIO.openIn x
val readline = TextIO.inputLine instream
fun aux readline n =
case readline of
NONE => (TextIO.closeIn instream; readFileList xs outstream n)
| SOME s => (TextIO.output(outstream, (getLineWriteCode s n));
aux (TextIO.inputLine instream) (n + 1))
in
aux readline n
end)
只需使用部分应用程序。邓诺(Dunno)为什么花这么长时间才弄清楚,但是行得通。我唯一想知道的是匿名lambda函数。我可以在其中放通配符之类的东西吗?
fun readFileList (x::xs) n outstream =
let
val part = readFileList xs n
val instream = TextIO.openIn x
val readline = TextIO.inputLine instream
fun aux readline n function =
case readline of
NONE => (TextIO.closeIn instream; function outstream)
| SOME s => (TextIO.output(outstream, (getLineWriteCode s n));
aux (TextIO.inputLine instream) (n + 1) (fn s => ()))
in
case xs of
[] => (aux readline n TextIO.closeOut)
| _ => (aux readline n part)
end