简体   繁体   中英

Is there an OCaml '@@' operator, and what does it mean?

I'm an OCaml n00b and trying to make sense of the following source file:

https://github.com/BinaryAnalysisPlatform/bap/blob/master/lib/bap_disasm/bap_disasm_shingled.ml

On line 46 there is the following code:

let static_successors gmin gmax lmem insn =
  let fall_through =
    if not (is_exec_ok gmin gmax lmem) then [None, `Fall]
    else
      let i = Word.((Memory.min_addr lmem) ++ (Memory.length lmem)) in      
      [Some i, `Fall] in
  if (Insn.may_affect_control_flow insn) then (
    let targets = (Insn.bil insn |> dests_of_bil) in
    if (not @@ Insn.is_unconditional_jump insn) then
      List.append fall_through targets
    else
      targets
  ) else fall_through

I'm getting the gist of most of this function, but the if (not @@ Insn.is_unconditional_jump insn part is stumping me. I can't seem to find a reference for the @@ operator/function; it seems to be applying the function to the instance insn somehow.

So, is @@ a built-in operator, if so what does it do? If not, how would I find the declaration for the operator/function, so I can hunt it down and figure it out?

This operator was introduced in Pervasives (the "always opened" module) in 4.01.

Basically, it is of type ('a -> 'b) -> 'a -> 'b . So f @@ x is equivalent to fx .

The good thing is its associativity and precedence.

In this specific case, not @@ Insn.is_unconditional_jump insn is exactly the same as not (Insn.is_unconditional_jump insn) .

It is declared as an internal primitive, so that would not help you much, but you can see the informations about it in the OCaml manual .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM