Toplevel中的OCaml双分号错误

Krp*_*non 0 ocaml syntax-error

我在OCaml顶层接收到这个奇怪的语法错误.

# #use "ex_8_4.ml";;
type blob = {
  get : unit -> float * float;
  area : unit -> float;
  set : float * float -> unit;
  move : float * float -> unit;
}
val new_rectangle : float -> float -> float -> float -> blob = <fun>
# let rect1 = new_rectangle 0.0 0.0 1.0 1.0 in  
  let rect2 = {rect1 with set = (fun _ -> ())};;
Error: Syntax error
Run Code Online (Sandbox Code Playgroud)

复制未能包括分号在错误中加下划线.

Ion*_*tan 5

之所以会发生这种情况,因为toplevel需要一个in关键字而不是分号:

> let a = 1 in let b = 2;;
Error: Syntax error
Run Code Online (Sandbox Code Playgroud)

一个修复是in在最后添加一个:

> let a = 1 in let b = 2 in a + b;;
- : int = 3
Run Code Online (Sandbox Code Playgroud)

但最简单的是结束每个让分号绑定:

> let a = 1;;
val a : int = 1
> let b = 2;;
val b : int = 2
> a + b;;
- : int = 3
Run Code Online (Sandbox Code Playgroud)