【发布时间】:2020-04-22 07:11:33
【问题描述】:
是否可以将此辅助函数参数化以接受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)
【问题讨论】:
标签: function functional-programming sml smlnj