Ocaml 语法错误

发布于 2024-08-11 00:14:54 字数 745 浏览 1 评论 0原文

这段代码有什么问题?我无法弄清楚:

let parent  (rules : grammar) (symbol1 : string) (symbol2 : string) : (SymbolSet.t) = 
  try
    SymbolSet.singleton (getParent [symbol1; symbol2] rules)
  with
      Not_found -> SymbolSet.singleton "";;

let fundementalRule (set1 : SymbolSet) (set2 : SymbolSet) (rules : grammar) : (SymbolSet) =
  allpairs (parent rules) set1 set2;;    

  Characters 20-21:
  let fundementalRule (set1 : SymbolSet) (set2 : SymbolSet) (rules : grammar) : (SymbolSet) =
                      ^
Syntax error: ')' expected, the highlighted '(' might be unmatched

括号是匹配的。那么是什么原因导致这个问题呢?

这很好:

let fundementalRule set1 set2 rules =
  allpairs (parent rules) set1 set2;;

What's wrong with this code? I can't figure it out:

let parent  (rules : grammar) (symbol1 : string) (symbol2 : string) : (SymbolSet.t) = 
  try
    SymbolSet.singleton (getParent [symbol1; symbol2] rules)
  with
      Not_found -> SymbolSet.singleton "";;

let fundementalRule (set1 : SymbolSet) (set2 : SymbolSet) (rules : grammar) : (SymbolSet) =
  allpairs (parent rules) set1 set2;;    

  Characters 20-21:
  let fundementalRule (set1 : SymbolSet) (set2 : SymbolSet) (rules : grammar) : (SymbolSet) =
                      ^
Syntax error: ')' expected, the highlighted '(' might be unmatched

The parenthesis is matched. What then is causing this issue?

This is just fine:

let fundementalRule set1 set2 rules =
  allpairs (parent rules) set1 set2;;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

网白 2024-08-18 00:14:54

也许类型应该是 SymbolSet.t 而不是 SymbolSet

maybe the types should be SymbolSet.t instead of SymbolSet

泪意 2024-08-18 00:14:54

上面那行是什么?我敢打赌,在这段代码之前的某个地方有一个不匹配的括号。

更新

我的直觉告诉我错误就在这里:

SymbolSet.singleton (getParent [symbol1; symbol2] rules)

我没有任何方法来测试此代码,但是当我尝试运行此代码时确实收到错误:

# let foo arg1 listarg arg2 = ();;
val foo : 'a -> 'b -> 'c -> unit = <fun>
# foo (1 [1; 2] 2);;
Error: This expression is not a function; it cannot be applied

我认为应该是这样的:

SymbolSet.singleton getParent [symbol1; symbol2] rules

What's on the line above it? I'd be willing to bet that there is an unmatched paren somewhere before this code.

Update

My intuition is telling me that the error is here:

SymbolSet.singleton (getParent [symbol1; symbol2] rules)

I don't have any way to test this code, but I do get an error when I try to run this code:

# let foo arg1 listarg arg2 = ();;
val foo : 'a -> 'b -> 'c -> unit = <fun>
# foo (1 [1; 2] 2);;
Error: This expression is not a function; it cannot be applied

I think that should be this:

SymbolSet.singleton getParent [symbol1; symbol2] rules
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文