Search code examples
haskellocamloperator-precedence

Equivalent of Haskell's $ operator in OCaml


Is there an equivalent to Haskell's $ operator in OCaml, or do I have to rely on brackets? See for example,

multiplyByFive 5 + 1 -- 26

but

multiplyByFive $ 5 + 1 -- 30

Solution

  • The standard library defines both a right-to-left application operator @@

    let compose h g f x = h @@ g @@ f x
    

    and left-to-right application operator |>:

    let rev_compose f g h x = x |> f |> g |> h
    

    with the expected associativity (right for @@ and left for |>).