将F#管道运算符(< |,>> ;、<<)转换为OCaml [英] Converting F# pipeline operators ( <|, >>, << ) to OCaml
本文介绍了将F#管道运算符(< |,>> ;、<<)转换为OCaml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将一些F#代码转换为OCaml,例如,我看到此管道运算符<|
有很多用途:
I'm converting some F# code to OCaml and I see a lot of uses of this pipeline operator <|
, for example:
let printPeg expr =
printfn "%s" <| pegToString expr
<|
运算符显然定义为:
# let ( <| ) a b = a b ;;
val ( <| ) : ('a -> 'b) -> 'a -> 'b = <fun>
我想知道为什么他们要麻烦地在F#中定义和使用此运算符,仅仅是为了避免出现这样的括号吗?:
I'm wondering why they bother to define and use this operator in F#, is it just so they can avoid putting in parens like this?:
let printPeg expr =
Printf.printf "%s" ( pegToString expr )
据我所知,这就是上面的F#代码到OCaml的转换,对吗?
As far as I can tell, that would be the conversion of the F# code above to OCaml, correct?
此外,我如何在Ocaml中实现F#的<<
和>>
运算符?
Also, how would I implement F#'s <<
and >>
operators in Ocaml?
(|>
运算符似乎只是:let ( |> ) a b = b a ;;
)
推荐答案
直接从 查看全文