【问题标题】:OCaml - Why does this declaration work when not associated with a variable name?OCaml - 为什么这个声明在不与变量名关联时有效?
【发布时间】:2017-10-08 06:51:42
【问题描述】:

我正在尝试编写一个函数,该函数将元组作为参数,如果元组的第二个成员等于 1、2 或 3,则返回 true。 通过返回我期望的类型来执行此操作就可以了:

# fun (x, y) -> match (x, y) with
      | (x, (1 | 2 | 3)) -> true
      | (x, _) -> false;;
- : 'a * int -> bool = <fun>

我希望能够通过将函数绑定到变量来实际测试该函数,但我得到一个语法错误,其中try 带有下划线:

# let try = fun (x, y) -> match (x, y) with
    | (x, (1 | 2 | 3)) -> true
    | (x, _) -> false;;
Error: Syntax error

【问题讨论】:

    标签: syntax-error ocaml


    【解决方案1】:

    try 是用于异常处理的关键字。您需要为您的函数选择另一个名称。

    【讨论】:

    • 谢谢,我不知道! test 到时候就到了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-17
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多