语法错误:预期为“)”,突出显示的“(”可能不匹配

问题描述 投票:0回答:1

我输入了这个表达式:

 let p_one : int ref = ref 1 ;;
 let p_two() : int ref = ref 2 ;;
 let p_three() : int ref = ref 3 ;;
 let accumulate() ( p_one() , p_two() , p_three() : int ref*int ref*int ref ) : unit() =
     ( p_one() , ( !p_two() + !p_one() ) , ( !p_one() + !p_two() + !p_three() )) ;;

Ocaml 解释器向我发送此错误:语法错误:预期为 ')',突出显示的 '(' 可能不匹配(与第三个括号中的 '(' )。 我不明白为什么??

我的练习是: 定义 3 个可变整型变量:一、二和三。编写一个单元类型的累加表达式(单个表达式),它通过累加 3 个变量的值来更新它们。因此,执行表达式后,变量一保持不变,变量二包含前 2 个值的总和,变量三包含前 2 个值的总和。例如,如果我们分别用整数值1、2和3初始化变量一、二和三,则执行后这3个变量分别包含值1、3和6。测试先前值的累积表达式。

algorithm ocaml
1个回答
0
投票

正如编译器所述:

File "test.ml", line 1, characters 24-25:
1 | let accumulate() ( p_one() , p_two() , p_three() : int ref*int ref*int ref ) : unit() =
                            ^
Error: Syntax error: ')' expected
File "test.ml", line 1, characters 17-18:
1 | let accumulate() ( p_one() , p_two() , p_three() : int ref*int ref*int ref ) : unit() =
                     ^
  This '(' might be unmatched

模式

p_one ()
在语法上无效,类型
unit ()
也无效。

© www.soinside.com 2019 - 2024. All rights reserved.