如何使用组合运算符修改代码?
How to modify a code with composition operator?
我想稍微修改一下this code的以下功能:
let find_context = function
| InputNeeded env ->
pop_until element_contains_prediction_items env
(* (pop_until element_contains_prediction_items env, current_state_number env) *)
| _ ->
assert false
... ...
let contextual_error_msg lexer checkpoint continuation =
find_context checkpoint |> fun nonterminals ->
Error.error "parsing" (Lexer.current_position lexer)
(Printf.sprintf "Error while analyzing %s."
(String.concat " or " (List.map Symbol.string_of_symbol nonterminals)))
@@ continuation
let resume_on_error last_reduction lex =
(* let resume_on_error last_reduction lex currentStateNumber = *)
match last_reduction with
... ...
let rec on_error last_reduction lexer checkpoint =
contextual_error_msg lexer checkpoint (fun () ->
resume_on_error last_reduction lexer
)
我打算也让find_context
到return当前状态号(上面注释了预期的代码),并让这个当前状态号最终传递给resume_on_error
(上面注释了预期的代码)。
但是我修改contextual_error_msg
和on_error
有困难; continuation
让事情变得复杂;我不知道在这里使用 @@
的目的是什么。
有人能帮忙吗?
您可以在此处检查运算符优先级:https://ocaml.org/api/Ocaml_operators.html
@@
优先于 |>
这是一个例子:
utop # let foo = 3. |> fun x y -> x +. 2.*.y @@ 1.;;
Error: This expression has type float but an expression was expected of type
'a -> 'b
─( 14:42:53 )─< command 11 >─────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # let bar = 3. |> fun x y -> x +. 2.*.y 1.;;
- : (float -> float) -> float = <fun>
foo
被解释为
(fun x y -> (x +. 2. *. y ) 1.) 3.
和bar
作为
(fun x y -> x +. 2 *. (y 1.)) 3.
也就是
fun y -> 3 +. 2 *. y 1.
我想稍微修改一下this code的以下功能:
let find_context = function
| InputNeeded env ->
pop_until element_contains_prediction_items env
(* (pop_until element_contains_prediction_items env, current_state_number env) *)
| _ ->
assert false
... ...
let contextual_error_msg lexer checkpoint continuation =
find_context checkpoint |> fun nonterminals ->
Error.error "parsing" (Lexer.current_position lexer)
(Printf.sprintf "Error while analyzing %s."
(String.concat " or " (List.map Symbol.string_of_symbol nonterminals)))
@@ continuation
let resume_on_error last_reduction lex =
(* let resume_on_error last_reduction lex currentStateNumber = *)
match last_reduction with
... ...
let rec on_error last_reduction lexer checkpoint =
contextual_error_msg lexer checkpoint (fun () ->
resume_on_error last_reduction lexer
)
我打算也让find_context
到return当前状态号(上面注释了预期的代码),并让这个当前状态号最终传递给resume_on_error
(上面注释了预期的代码)。
但是我修改contextual_error_msg
和on_error
有困难; continuation
让事情变得复杂;我不知道在这里使用 @@
的目的是什么。
有人能帮忙吗?
您可以在此处检查运算符优先级:https://ocaml.org/api/Ocaml_operators.html
@@
优先于 |>
这是一个例子:
utop # let foo = 3. |> fun x y -> x +. 2.*.y @@ 1.;;
Error: This expression has type float but an expression was expected of type
'a -> 'b
─( 14:42:53 )─< command 11 >─────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # let bar = 3. |> fun x y -> x +. 2.*.y 1.;;
- : (float -> float) -> float = <fun>
foo
被解释为
(fun x y -> (x +. 2. *. y ) 1.) 3.
和bar
作为
(fun x y -> x +. 2 *. (y 1.)) 3.
也就是
fun y -> 3 +. 2 *. y 1.