Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ocaml

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?

like image 980
John Källén Avatar asked Oct 28 '15 15:10

John Källén


1 Answers

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 f x.

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.

like image 191
PatJ Avatar answered Sep 24 '22 12:09

PatJ