如何参数化此函数以接受函数和 TextIO.closeOut 作为输入?

How can I parametrize this function to accept a function and TextIO.closeOut as input?

是否可以参数化此辅助功能以接受 TextIO.closeOut outstreamreadFileList xs outstream n 作为输入?或者我必须在 TextIO 中使用该追加函数才能使函数体不那么丑陋吗?是否可以匹配他们的类型?

两个主体本质上是一样的,唯一的区别是NONE情况下的第二个return函数。

    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)

只是不得不使用部分应用程序。不知道为什么花了这么长时间才弄清楚,但它确实有效。我唯一想知道的是匿名 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