【问题标题】:How to write mutually recursive functions within a let binding in SML?如何在 SML 的 let 绑定中编写相互递归的函数?
【发布时间】:2012-04-29 07:31:49
【问题描述】:

我想做这样的事情:

fun f () =
    let
      fun a() = b()
    and
      fun b() = a()
    in
      ()
    end

其中 a 和 b 是有意义的相互递归函数。但是,这给出了:

Error: syntax error: replacing  AND with  SEMICOLON

有什么办法吗?

【问题讨论】:

    标签: sml smlnj


    【解决方案1】:

    SML 中相互递归函数的声明由fun ... and ... 块标记:

    fun f () =
      let
        fun a() = b()
        and b() = a() (* There is no 'fun' keyword before b() *)
      in
        ()
      end
    

    【讨论】:

    • 解释器对“local”很生气,但是用 let 替换 local(即,摆脱我代码中的第二个乐趣)似乎有效。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 2020-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    相关资源
    最近更新 更多